pgp fixes and revert configuration changes

This commit is contained in:
Daniel Gultsch 2015-11-25 20:47:02 +01:00
parent 8228e82f51
commit a557d38e4d
16 changed files with 91 additions and 134 deletions

View File

@ -39,7 +39,6 @@
<activity
android:name=".ui.ConversationActivity"
android:label="@string/app_name"
android:configChanges="orientation|screenSize"
android:launchMode="singleTask"
android:windowSoftInputMode="stateHidden">
<intent-filter>
@ -91,22 +90,18 @@
android:label="@string/change_password_on_server"/>
<activity
android:name=".ui.ManageAccountActivity"
android:configChanges="orientation|screenSize"
android:label="@string/title_activity_manage_accounts"
android:launchMode="singleTask"/>
<activity
android:name=".ui.EditAccountActivity"
android:configChanges="orientation|screenSize"
android:launchMode="singleTask"
android:windowSoftInputMode="stateHidden|adjustResize"/>
<activity
android:name=".ui.ConferenceDetailsActivity"
android:configChanges="orientation|screenSize"
android:label="@string/title_activity_conference_details"
android:windowSoftInputMode="stateHidden"/>
<activity
android:name=".ui.ContactDetailsActivity"
android:configChanges="orientation|screenSize"
android:label="@string/title_activity_contact_details"
android:windowSoftInputMode="stateHidden"/>
<activity

View File

@ -37,7 +37,8 @@ public final class Config {
public static final int REFRESH_UI_INTERVAL = 500;
public static final boolean NO_PROXY_LOOKUP = false; //useful to debug ibb
public static final boolean DISABLE_PROXY_LOOKUP = false; //useful to debug ibb
public static final boolean DISABLE_HTTP_UPLOAD = false;
public static final boolean DISABLE_STRING_PREP = false; // setting to true might increase startup performance
public static final boolean EXTENDED_SM_LOGGING = true; // log stanza counts
public static final boolean RESET_ATTEMPT_COUNT_ON_NETWORK_CHANGE = true; //setting to true might increase power consumption

View File

@ -24,6 +24,7 @@ import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.DownloadableFile;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.http.HttpConnectionManager;
import eu.siacs.conversations.persistance.FileBackend;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.ui.UiCallback;
@ -96,6 +97,7 @@ public class PgpEngine {
@Override
public void onReturn(Intent result) {
notifyPgpDecryptionService(message.getConversation().getAccount(), OpenPgpApi.ACTION_DECRYPT_VERIFY, result);
switch (result.getIntExtra(OpenPgpApi.RESULT_CODE,
OpenPgpApi.RESULT_CODE_ERROR)) {
case OpenPgpApi.RESULT_CODE_SUCCESS:
@ -196,8 +198,8 @@ public class PgpEngine {
.getFileBackend().getFile(message, false);
outputFile.getParentFile().mkdirs();
outputFile.createNewFile();
InputStream is = new FileInputStream(inputFile);
OutputStream os = new FileOutputStream(outputFile);
final InputStream is = new FileInputStream(inputFile);
final OutputStream os = new FileOutputStream(outputFile);
api.executeApiAsync(params, is, os, new IOpenPgpCallback() {
@Override
@ -206,6 +208,12 @@ public class PgpEngine {
switch (result.getIntExtra(OpenPgpApi.RESULT_CODE,
OpenPgpApi.RESULT_CODE_ERROR)) {
case OpenPgpApi.RESULT_CODE_SUCCESS:
try {
os.flush();
} catch (IOException ignored) {
//ignored
}
FileBackend.close(os);
callback.success(message);
break;
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:

View File

@ -523,7 +523,7 @@ public class Message extends AbstractEntity {
String extension = filename.substring(dotPosition + 1);
// we want the real file extension, not the crypto one
if (Arrays.asList(Transferable.VALID_CRYPTO_EXTENSIONS).contains(extension)) {
return extractRelevantExtension(path.substring(0,dotPosition));
return extractRelevantExtension(filename.substring(0,dotPosition));
} else {
return extension;
}

View File

@ -107,10 +107,6 @@ public class MucOptions {
}
public interface OnJoinListener extends OnEventListener {
}
public class User {
private Role role = Role.NONE;
private Affiliation affiliation = Affiliation.NONE;
@ -215,7 +211,6 @@ public class MucOptions {
private boolean isOnline = false;
private int error = ERROR_UNKNOWN;
private OnRenameListener onRenameListener = null;
private OnJoinListener onJoinListener = null;
private User self = new User();
private String subject = null;
private String password = null;
@ -317,9 +312,6 @@ public class MucOptions {
onRenameListener.onSuccess();
}
mNickChangingInProgress = false;
} else if (this.onJoinListener != null) {
this.onJoinListener.onSuccess();
this.onJoinListener = null;
}
} else {
addUser(user);
@ -328,14 +320,11 @@ public class MucOptions {
Element signed = packet.findChild("x", "jabber:x:signed");
if (signed != null) {
Element status = packet.findChild("status");
String msg;
if (status != null) {
msg = status.getContent();
} else {
msg = "";
String msg = status == null ? "" : status.getContent();
long keyId = pgp.fetchKeyId(account, msg, signed.getContent());
if (keyId != 0) {
user.setPgpKeyId(keyId);
}
user.setPgpKeyId(pgp.fetchKeyId(account, msg,
signed.getContent()));
}
}
}
@ -381,10 +370,6 @@ public class MucOptions {
private void setError(int error) {
this.isOnline = false;
this.error = error;
if (onJoinListener != null) {
onJoinListener.onFailure();
onJoinListener = null;
}
}
private List<String> getStatusCodes(Element x) {
@ -438,10 +423,6 @@ public class MucOptions {
this.onRenameListener = listener;
}
public void setOnJoinListener(OnJoinListener listener) {
this.onJoinListener = listener;
}
public void setOffline() {
this.users.clear();
this.error = 0;

View File

@ -125,6 +125,9 @@ public class HttpDownloadConnection implements Transferable {
mXmppConnectionService.sendBroadcast(intent);
message.setTransferable(null);
mHttpConnectionManager.finishConnection(this);
if (message.getEncryption() == Message.ENCRYPTION_PGP) {
message.getConversation().getAccount().getPgpDecryptionService().add(message);
}
mXmppConnectionService.updateConversationUi();
if (acceptedAutomatically) {
mXmppConnectionService.getNotificationService().push(message);

View File

@ -61,22 +61,26 @@ public class FileBackend {
final boolean encrypted = !decrypted
&& (message.getEncryption() == Message.ENCRYPTION_PGP
|| message.getEncryption() == Message.ENCRYPTION_DECRYPTED);
if (encrypted) {
return new DownloadableFile(getConversationsFileDirectory()+message.getUuid()+".pgp");
final DownloadableFile file;
String path = message.getRelativeFilePath();
if (path == null) {
path = message.getUuid();
}
if (path.startsWith("/")) {
file = new DownloadableFile(path);
} else {
String path = message.getRelativeFilePath();
if (path == null) {
path = message.getUuid();
} else if (path.startsWith("/")) {
return new DownloadableFile(path);
}
String mime = message.getMimeType();
if (mime != null && mime.startsWith("image")) {
return new DownloadableFile(getConversationsImageDirectory() + path);
file = new DownloadableFile(getConversationsImageDirectory() + path);
} else {
return new DownloadableFile(getConversationsFileDirectory() + path);
file = new DownloadableFile(getConversationsFileDirectory() + path);
}
}
if (encrypted) {
return new DownloadableFile(getConversationsFileDirectory() + file.getName() + ".pgp");
} else {
return file;
}
}
public static String getConversationsFileDirectory() {

View File

@ -1688,16 +1688,16 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
List<Conversation> conversations = getConversations();
for (Conversation conversation : conversations) {
if (conversation.getMode() == Conversation.MODE_MULTI && conversation.getAccount() == account) {
joinMuc(conversation, true);
joinMuc(conversation, true, null);
}
}
}
public void joinMuc(Conversation conversation) {
joinMuc(conversation, false);
joinMuc(conversation, false, null);
}
private void joinMuc(Conversation conversation, boolean now) {
private void joinMuc(Conversation conversation, boolean now, final OnConferenceJoined onConferenceJoined) {
Account account = conversation.getAccount();
account.pendingConferenceJoins.remove(conversation);
account.pendingConferenceLeaves.remove(conversation);
@ -1730,11 +1730,13 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
String sig = account.getPgpSignature();
if (sig != null) {
packet.addChild("status").setContent("online");
packet.addChild("x", "jabber:x:signed").setContent(sig);
}
sendPresencePacket(account, packet);
fetchConferenceConfiguration(conversation);
if (onConferenceJoined != null) {
onConferenceJoined.onConferenceJoined(conversation);
}
if (!joinJid.equals(conversation.getJid())) {
conversation.setContactJid(joinJid);
databaseBackend.updateConversation(conversation);
@ -1752,17 +1754,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
@Override
public void onFetchFailed(final Conversation conversation, Element error) {
conversation.getMucOptions().setOnJoinListener(new MucOptions.OnJoinListener() {
@Override
public void onSuccess() {
fetchConferenceConfiguration(conversation);
}
@Override
public void onFailure() {
}
});
join(conversation);
}
});
@ -1889,34 +1880,37 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
String name = new BigInteger(75, getRNG()).toString(32);
Jid jid = Jid.fromParts(name, server, null);
final Conversation conversation = findOrCreateConversation(account, jid, true);
joinMuc(conversation);
Bundle options = new Bundle();
options.putString("muc#roomconfig_persistentroom", "1");
options.putString("muc#roomconfig_membersonly", "1");
options.putString("muc#roomconfig_publicroom", "0");
options.putString("muc#roomconfig_whois", "anyone");
pushConferenceConfiguration(conversation, options, new OnConferenceOptionsPushed() {
joinMuc(conversation, true, new OnConferenceJoined() {
@Override
public void onPushSucceeded() {
for (Jid invite : jids) {
invite(conversation, invite);
}
if (account.countPresences() > 1) {
directInvite(conversation, account.getJid().toBareJid());
}
if (callback != null) {
callback.success(conversation);
}
}
public void onConferenceJoined(final Conversation conversation) {
Bundle options = new Bundle();
options.putString("muc#roomconfig_persistentroom", "1");
options.putString("muc#roomconfig_membersonly", "1");
options.putString("muc#roomconfig_publicroom", "0");
options.putString("muc#roomconfig_whois", "anyone");
pushConferenceConfiguration(conversation, options, new OnConferenceOptionsPushed() {
@Override
public void onPushSucceeded() {
for (Jid invite : jids) {
invite(conversation, invite);
}
if (account.countPresences() > 1) {
directInvite(conversation, account.getJid().toBareJid());
}
if (callback != null) {
callback.success(conversation);
}
}
@Override
public void onPushFailed() {
if (callback != null) {
callback.error(R.string.conference_creation_failed, conversation);
}
@Override
public void onPushFailed() {
if (callback != null) {
callback.error(R.string.conference_creation_failed, conversation);
}
}
});
}
});
} catch (InvalidJidException e) {
if (callback != null) {
callback.error(R.string.conference_creation_failed, null);
@ -2976,6 +2970,10 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
void onFetchFailed(Conversation conversation, Element error);
}
public interface OnConferenceJoined {
void onConferenceJoined(Conversation conversation);
}
public interface OnConferenceOptionsPushed {
void onPushSucceeded();

View File

@ -6,7 +6,6 @@ import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.IntentSender.SendIntentException;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.os.Build;
import android.os.Bundle;
@ -42,7 +41,6 @@ import eu.siacs.conversations.entities.MucOptions.User;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdate;
import eu.siacs.conversations.services.XmppConnectionService.OnMucRosterUpdate;
import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.xmpp.jid.Jid;
public class ConferenceDetailsActivity extends XmppActivity implements OnConversationUpdate, OnMucRosterUpdate, XmppConnectionService.OnAffiliationChanged, XmppConnectionService.OnRoleChanged, XmppConnectionService.OnConferenceOptionsPushed {
@ -55,7 +53,6 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
inviteToConversation(mConversation);
}
};
private LinearLayout mMainLayout;
private TextView mYourNick;
private ImageView mYourPhoto;
private ImageButton mEditNickButton;
@ -190,7 +187,6 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_muc_details);
mMainLayout = (LinearLayout) findViewById(R.id.muc_main_layout);
mYourNick = (TextView) findViewById(R.id.muc_your_nick);
mYourPhoto = (ImageView) findViewById(R.id.your_photo);
mEditNickButton = (ImageButton) findViewById(R.id.edit_nick_button);
@ -454,12 +450,6 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
}
}
@Override
public void onConfigurationChanged (Configuration newConfig) {
super.onConfigurationChanged(newConfig);
UIHelper.resetChildMargins(mMainLayout);
}
private void updateView() {
final MucOptions mucOptions = mConversation.getMucOptions();
final User self = mucOptions.getSelf();

View File

@ -7,7 +7,6 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
@ -100,7 +99,6 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
}
}
};
private LinearLayout mainLayout;
private Jid accountJid;
private Jid contactJid;
private TextView contactJidTv;
@ -199,7 +197,6 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
this.messageFingerprint = getIntent().getStringExtra("fingerprint");
setContentView(R.layout.activity_contact_details);
mainLayout = (LinearLayout) findViewById(R.id.details_main_layout);
contactJidTv = (TextView) findViewById(R.id.details_contactjid);
accountJidTv = (TextView) findViewById(R.id.details_account);
lastseen = (TextView) findViewById(R.id.details_lastseen);
@ -300,12 +297,6 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
return true;
}
@Override
public void onConfigurationChanged (Configuration newConfig) {
super.onConfigurationChanged(newConfig);
UIHelper.resetChildMargins(mainLayout);
}
private void populateView() {
invalidateOptionsMenu();
setTitle(contact.getDisplayName());

View File

@ -17,6 +17,7 @@ import android.provider.MediaStore;
import android.support.v4.widget.SlidingPaneLayout;
import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
@ -510,22 +511,22 @@ public class ConversationActivity extends XmppActivity
}
final Conversation conversation = getSelectedConversation();
final int encryption = conversation.getNextEncryption();
final int mode = conversation.getMode();
if (encryption == Message.ENCRYPTION_PGP) {
if (hasPgp()) {
if (conversation.getContact().getPgpKeyId() != 0) {
if (mode == Conversation.MODE_SINGLE && conversation.getContact().getPgpKeyId() != 0) {
xmppConnectionService.getPgpEngine().hasKey(
conversation.getContact(),
new UiCallback<Contact>() {
@Override
public void userInputRequried(PendingIntent pi,
Contact contact) {
ConversationActivity.this.runIntent(pi,attachmentChoice);
public void userInputRequried(PendingIntent pi, Contact contact) {
ConversationActivity.this.runIntent(pi, attachmentChoice);
}
@Override
public void success(Contact contact) {
selectPresenceToAttachFile(attachmentChoice,encryption);
selectPresenceToAttachFile(attachmentChoice, encryption);
}
@Override
@ -533,6 +534,16 @@ public class ConversationActivity extends XmppActivity
displayErrorDialog(error);
}
});
} else if (mode == Conversation.MODE_MULTI && conversation.getMucOptions().pgpKeysInUse()) {
if (!conversation.getMucOptions().everybodyHasKeys()) {
Toast warning = Toast
.makeText(this,
R.string.missing_public_keys,
Toast.LENGTH_LONG);
warning.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
warning.show();
}
selectPresenceToAttachFile(attachmentChoice, encryption);
} else {
final ConversationFragment fragment = (ConversationFragment) getFragmentManager()
.findFragmentByTag("conversation");

View File

@ -482,12 +482,6 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
invalidateOptionsMenu();
}
@Override
public void onConfigurationChanged (Configuration newConfig) {
super.onConfigurationChanged(newConfig);
UIHelper.resetChildMargins(mMainLayout);
}
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
switch (item.getItemId()) {

View File

@ -3,11 +3,7 @@ package eu.siacs.conversations.utils;
import android.content.Context;
import android.text.format.DateFormat;
import android.text.format.DateUtils;
import android.util.DisplayMetrics;
import android.util.Pair;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import java.util.ArrayList;
import java.util.Arrays;
@ -265,21 +261,4 @@ public class UIHelper {
body = body.replace("?","").replace("¿","");
return LOCATION_QUESTIONS.contains(body);
}
public static void resetChildMargins(LinearLayout view) {
int childCount = view.getChildCount();
for (int i = 0; i < childCount; i++) {
UIHelper.resetMargins(view.getChildAt(i));
}
}
private static void resetMargins(View view) {
LinearLayout.MarginLayoutParams marginLayoutParams = new LinearLayout.MarginLayoutParams(view.getLayoutParams());
marginLayoutParams.setMargins(view.getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin),
view.getResources().getDimensionPixelSize(R.dimen.activity_vertical_margin),
view.getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin),
view.getResources().getDimensionPixelSize(R.dimen.activity_vertical_margin));
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(marginLayoutParams);
view.setLayoutParams(layoutParams);
}
}

View File

@ -1369,7 +1369,7 @@ public class XmppConnection implements Runnable {
}
public boolean httpUpload() {
return findDiscoItemsByFeature(Xmlns.HTTP_UPLOAD).size() > 0;
return !Config.DISABLE_HTTP_UPLOAD && findDiscoItemsByFeature(Xmlns.HTTP_UPLOAD).size() > 0;
}
}

View File

@ -114,6 +114,8 @@ public class JingleConnection implements Transferable {
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(file));
mXmppConnectionService.sendBroadcast(intent);
} else {
account.getPgpDecryptionService().add(message);
}
}

View File

@ -83,7 +83,7 @@ public class JingleConnectionManager extends AbstractConnectionManager {
public void getPrimaryCandidate(Account account,
final OnPrimaryCandidateFound listener) {
if (Config.NO_PROXY_LOOKUP) {
if (Config.DISABLE_PROXY_LOOKUP) {
listener.onPrimaryCandidateFound(false, null);
return;
}