offer to announce pgp key if pgp encryption is selected from menu

This commit is contained in:
Daniel Gultsch 2014-05-08 14:35:21 +02:00
parent 0ed29c1c77
commit 99a56a2bde
3 changed files with 50 additions and 42 deletions

View file

@ -423,7 +423,7 @@ public class ConversationActivity extends XmppActivity {
startActivity(inviteIntent);
break;
case R.id.action_security:
final Conversation selConv = getSelectedConversation();
final Conversation conversation = getSelectedConversation();
View menuItemView = findViewById(R.id.action_security);
PopupMenu popup = new PopupMenu(this, menuItemView);
final ConversationFragment fragment = (ConversationFragment) getFragmentManager()
@ -435,19 +435,25 @@ public class ConversationActivity extends XmppActivity {
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.encryption_choice_none:
selConv.setNextEncryption(Message.ENCRYPTION_NONE);
conversation.setNextEncryption(Message.ENCRYPTION_NONE);
item.setChecked(true);
break;
case R.id.encryption_choice_otr:
selConv.setNextEncryption(Message.ENCRYPTION_OTR);
conversation.setNextEncryption(Message.ENCRYPTION_OTR);
item.setChecked(true);
break;
case R.id.encryption_choice_pgp:
selConv.setNextEncryption(Message.ENCRYPTION_PGP);
item.setChecked(true);
if (hasPgp()) {
if (conversation.getAccount().getKeys().has("pgp_signature")) {
conversation.setNextEncryption(Message.ENCRYPTION_PGP);
item.setChecked(true);
} else {
announcePgp(conversation.getAccount());
}
}
break;
default:
selConv.setNextEncryption(Message.ENCRYPTION_NONE);
conversation.setNextEncryption(Message.ENCRYPTION_NONE);
break;
}
fragment.updateChatMsgHint();
@ -455,7 +461,7 @@ public class ConversationActivity extends XmppActivity {
}
});
popup.inflate(R.menu.encryption_choices);
switch (selConv.getNextEncryption()) {
switch (conversation.getNextEncryption()) {
case Message.ENCRYPTION_NONE:
popup.getMenu().findItem(R.id.encryption_choice_none)
.setChecked(true);
@ -468,10 +474,6 @@ public class ConversationActivity extends XmppActivity {
popup.getMenu().findItem(R.id.encryption_choice_pgp)
.setChecked(true);
break;
case Message.ENCRYPTION_DECRYPTED:
popup.getMenu().findItem(R.id.encryption_choice_pgp)
.setChecked(true);
break;
default:
popup.getMenu().findItem(R.id.encryption_choice_none)
.setChecked(true);

View file

@ -38,8 +38,6 @@ import android.widget.ListView;
import android.widget.TextView;
public class ManageAccountActivity extends XmppActivity {
public static final int REQUEST_ANNOUNCE_PGP = 0x73731;
protected boolean isActionMode = false;
protected ActionMode actionMode;
@ -281,7 +279,7 @@ public class ManageAccountActivity extends XmppActivity {
} else if (item.getItemId()==R.id.mgmt_account_announce_pgp) {
if (activity.hasPgp()) {
mode.finish();
announcePgp();
announcePgp(selectedAccountForActionMode);
}
} else if (item.getItemId() == R.id.mgmt_otr_key) {
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
@ -361,33 +359,6 @@ public class ManageAccountActivity extends XmppActivity {
}
});
}
private void announcePgp() {
final Account account = selectedAccountForActionMode;
xmppConnectionService.getPgpEngine().generateSignature(account, "online", new OnPgpEngineResult() {
@Override
public void userInputRequried(PendingIntent pi) {
try {
startIntentSenderForResult(pi.getIntentSender(), REQUEST_ANNOUNCE_PGP, null, 0, 0, 0);
} catch (SendIntentException e) {
Log.d("xmppService","coulnd start intent for pgp anncouncment");
}
}
@Override
public void success() {
xmppConnectionService.databaseBackend.updateAccount(account);
xmppConnectionService.sendPgpPresence(account, account.getPgpSignature());
}
@Override
public void error(OpenPgpError openPgpError) {
// TODO Auto-generated method stub
}
});
}
@Override
protected void onStop() {
@ -487,7 +458,7 @@ public class ManageAccountActivity extends XmppActivity {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (requestCode == REQUEST_ANNOUNCE_PGP) {
announcePgp();
announcePgp(selectedAccountForActionMode);
}
}
}

View file

@ -1,28 +1,37 @@
package eu.siacs.conversations.ui;
import org.openintents.openpgp.OpenPgpError;
import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.OnPgpEngineResult;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.services.XmppConnectionService.XmppConnectionBinder;
import eu.siacs.conversations.utils.ExceptionHelper;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.PendingIntent;
import android.app.AlertDialog.Builder;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.IntentSender.SendIntentException;
import android.content.Intent;
import android.content.ServiceConnection;
import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
public abstract class XmppActivity extends Activity {
public static final int REQUEST_ANNOUNCE_PGP = 0x73731;
protected final static String LOGTAG = "xmppService";
public XmppConnectionService xmppConnectionService;
@ -152,4 +161,30 @@ public abstract class XmppActivity extends Activity {
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(viewConversationIntent);
}
protected void announcePgp(final Account account) {
xmppConnectionService.getPgpEngine().generateSignature(account, "online", new OnPgpEngineResult() {
@Override
public void userInputRequried(PendingIntent pi) {
try {
startIntentSenderForResult(pi.getIntentSender(), REQUEST_ANNOUNCE_PGP, null, 0, 0, 0);
} catch (SendIntentException e) {
Log.d("xmppService","coulnd start intent for pgp anncouncment");
}
}
@Override
public void success() {
xmppConnectionService.databaseBackend.updateAccount(account);
xmppConnectionService.sendPgpPresence(account, account.getPgpSignature());
}
@Override
public void error(OpenPgpError openPgpError) {
// TODO Auto-generated method stub
}
});
}
}