use logging framework in more places

This commit is contained in:
Daniel Gultsch 2023-02-16 12:58:52 +01:00
parent b0010307c0
commit a09cc126ea
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
9 changed files with 53 additions and 105 deletions

View file

@ -6,9 +6,10 @@ import androidx.room.Entity;
import androidx.room.ForeignKey;
import androidx.room.Index;
import androidx.room.PrimaryKey;
import eu.siacs.conversations.entities.MucOptions;
import im.conversations.android.database.model.PresenceShow;
import im.conversations.android.database.model.PresenceType;
import im.conversations.android.xmpp.model.muc.Affiliation;
import im.conversations.android.xmpp.model.muc.Role;
import org.jxmpp.jid.BareJid;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.parts.Resourcepart;
@ -54,9 +55,9 @@ public class PresenceEntity {
@Nullable public String occupantId;
@Nullable public MucOptions.Affiliation mucUserAffiliation;
@Nullable public Affiliation mucUserAffiliation;
@Nullable public MucOptions.Role mucUserRole;
@Nullable public Role mucUserRole;
@Nullable public Jid mucUserJid;

View file

@ -1,18 +1,20 @@
package im.conversations.android.xml;
import android.util.Log;
import android.util.Xml;
import eu.siacs.conversations.Config;
import im.conversations.android.xmpp.ExtensionFactory;
import im.conversations.android.xmpp.model.Extension;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
public class XmlReader implements Closeable {
private static final Logger LOGGER = LoggerFactory.getLogger(XmlReader.class);
private final XmlPullParser parser;
private InputStream is;
@ -20,19 +22,19 @@ public class XmlReader implements Closeable {
this.parser = Xml.newPullParser();
try {
this.parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
} catch (XmlPullParserException e) {
Log.d(Config.LOGTAG, "error setting namespace feature on parser");
} catch (final XmlPullParserException e) {
LOGGER.error("error setting namespace feature on parser", e);
}
}
public void setInputStream(InputStream inputStream) throws IOException {
public void setInputStream(final InputStream inputStream) throws IOException {
if (inputStream == null) {
throw new IOException();
}
this.is = inputStream;
try {
parser.setInput(new InputStreamReader(this.is));
} catch (XmlPullParserException e) {
this.parser.setInput(new InputStreamReader(this.is));
} catch (final XmlPullParserException e) {
throw new IOException("error resetting parser");
}
}

View file

@ -11,8 +11,6 @@ import com.google.common.collect.Sets;
import com.google.common.primitives.Ints;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.utils.PhoneHelper;
import im.conversations.android.Conversations;
import im.conversations.android.database.ConversationsDatabase;
import im.conversations.android.database.model.Account;
@ -33,6 +31,12 @@ public class ConnectionPool {
private static final Logger LOGGER = LoggerFactory.getLogger(ConnectionPool.class);
public static final int CONNECT_TIMEOUT = 90;
public static final int PING_MAX_INTERVAL = 300;
public static final int PING_MIN_INTERVAL = 30;
public static final int LOW_PING_TIMEOUT = 1; // used after push received
public static final int PING_TIMEOUT = 15;
private static volatile ConnectionPool INSTANCE;
private final Context context;
@ -148,7 +152,7 @@ public class ConnectionPool {
if (connection.supportsClientStateIndication()) {
// TODO send correct CSI state (connection.sendActive or connection.sendInactive)
}
scheduleWakeUpCall(Config.PING_MAX_INTERVAL);
scheduleWakeUpCall(PING_MAX_INTERVAL);
} else if (connection.getStatus() == ConnectionState.OFFLINE) {
// TODO previously we would call resetSendingToWaiting. The new architecture likely
@ -227,9 +231,7 @@ public class ConnectionPool {
// WakeLockHelper.acquire(wakeLock);
int pingNow = 0;
final HashSet<XmppConnection> pingCandidates = new HashSet<>();
final String androidId = PhoneHelper.getAndroidId(context);
for (final XmppConnection xmppConnection : this.connections) {
final Account account = xmppConnection.getAccount();
// TODO fix me if we bring back FCM push support
final boolean pushWasMeantForThisAccount = false;
if (processAccountState(xmppConnection, pushWasMeantForThisAccount, pingCandidates)) {
@ -242,7 +244,7 @@ public class ConnectionPool {
final boolean lowTimeout = isInLowPingTimeoutMode(account);
xmppConnection.sendPing();
LOGGER.debug("{}: send ping (lowTimeout={})", account.address, lowTimeout);
scheduleWakeUpCall(lowTimeout ? Config.LOW_PING_TIMEOUT : Config.PING_TIMEOUT);
scheduleWakeUpCall(lowTimeout ? LOW_PING_TIMEOUT : PING_TIMEOUT);
}
}
// WakeLockHelper.release(wakeLock);
@ -260,12 +262,12 @@ public class ConnectionPool {
final long lastReceived = connection.getLastPacketReceived();
final long lastSent = connection.getLastPingSent();
final long msToNextPing =
(Math.max(lastReceived, lastSent) + Config.PING_MAX_INTERVAL * 1000)
(Math.max(lastReceived, lastSent) + PING_MAX_INTERVAL * 1000)
- SystemClock.elapsedRealtime();
final int pingTimeout =
lowPingTimeoutMode.contains(account.address)
? Config.LOW_PING_TIMEOUT * 1000
: Config.PING_TIMEOUT * 1000;
? LOW_PING_TIMEOUT * 1000
: PING_TIMEOUT * 1000;
final long pingTimeoutIn =
(lastSent + pingTimeout) - SystemClock.elapsedRealtime();
if (lastSent > lastReceived) {
@ -297,7 +299,7 @@ public class ConnectionPool {
} else if (connection.getStatus() == ConnectionState.CONNECTING) {
long secondsSinceLastConnect =
(SystemClock.elapsedRealtime() - connection.getLastConnect()) / 1000;
long timeout = Config.CONNECT_TIMEOUT - secondsSinceLastConnect;
long timeout = CONNECT_TIMEOUT - secondsSinceLastConnect;
if (timeout < 0) {
LOGGER.debug(
"{}: time out during connect reconnecting (secondsSinceLast={})",
@ -322,7 +324,7 @@ public class ConnectionPool {
connection.prepareNewConnection();
connection.interrupt();
thread.start();
scheduleWakeUpCall(Config.CONNECT_DISCO_TIMEOUT);
scheduleWakeUpCall(PING_MAX_INTERVAL);
} else {
disconnect(connection, true);
connection.resetEverything();

View file

@ -1,8 +1,5 @@
package im.conversations.android.xmpp;
import androidx.annotation.StringRes;
import eu.siacs.conversations.R;
public enum ConnectionState {
OFFLINE(false),
CONNECTING(false),
@ -56,69 +53,4 @@ public enum ConnectionState {
public boolean isAttemptReconnect() {
return this.attemptReconnect;
}
// TODO refactor into DataBinder (we can print the enum directly in the UI)
@StringRes
public int getReadableId() {
switch (this) {
case ONLINE:
return R.string.account_status_online;
case CONNECTING:
return R.string.account_status_connecting;
case OFFLINE:
return R.string.account_status_offline;
case UNAUTHORIZED:
return R.string.account_status_unauthorized;
case SERVER_NOT_FOUND:
return R.string.account_status_not_found;
case REGISTRATION_FAILED:
return R.string.account_status_regis_fail;
case REGISTRATION_WEB:
return R.string.account_status_regis_web;
case REGISTRATION_CONFLICT:
return R.string.account_status_regis_conflict;
case REGISTRATION_SUCCESSFUL:
return R.string.account_status_regis_success;
case REGISTRATION_NOT_SUPPORTED:
return R.string.account_status_regis_not_sup;
case REGISTRATION_INVALID_TOKEN:
return R.string.account_status_regis_invalid_token;
case TLS_ERROR:
return R.string.account_status_tls_error;
case TLS_ERROR_DOMAIN:
return R.string.account_status_tls_error_domain;
case INCOMPATIBLE_SERVER:
return R.string.account_status_incompatible_server;
case INCOMPATIBLE_CLIENT:
return R.string.account_status_incompatible_client;
case TOR_NOT_AVAILABLE:
return R.string.account_status_tor_unavailable;
case BIND_FAILURE:
return R.string.account_status_bind_failure;
case SESSION_FAILURE:
return R.string.session_failure;
case DOWNGRADE_ATTACK:
return R.string.sasl_downgrade;
case HOST_UNKNOWN:
return R.string.account_status_host_unknown;
case POLICY_VIOLATION:
return R.string.account_status_policy_violation;
case REGISTRATION_PLEASE_WAIT:
return R.string.registration_please_wait;
case REGISTRATION_PASSWORD_TOO_WEAK:
return R.string.registration_password_too_weak;
case STREAM_ERROR:
return R.string.account_status_stream_error;
case STREAM_OPENING_ERROR:
return R.string.account_status_stream_opening_error;
case PAYMENT_REQUIRED:
return R.string.payment_required;
case MISSING_INTERNET_PERMISSION:
return R.string.missing_internet_permission;
case TEMPORARY_AUTH_FAILURE:
return R.string.account_status_temporary_auth_failure;
default:
return R.string.account_status_unknown;
}
}
}

View file

@ -0,0 +1,9 @@
package im.conversations.android.xmpp.model.muc;
public enum Affiliation {
OWNER,
ADMIN,
MEMBER,
OUTCAST,
NONE;
}

View file

@ -0,0 +1,8 @@
package im.conversations.android.xmpp.model.muc;
public enum Role {
MODERATOR,
VISITOR,
PARTICIPANT,
NONE
}

View file

@ -1,6 +1,5 @@
package im.conversations.android.xmpp.sasl;
import android.util.Log;
import com.google.common.base.CaseFormat;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicates;
@ -8,7 +7,6 @@ import com.google.common.base.Strings;
import com.google.common.collect.BiMap;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableBiMap;
import eu.siacs.conversations.Config;
import im.conversations.android.tls.SSLSockets;
import im.conversations.android.xml.Element;
import im.conversations.android.xml.Namespace;
@ -57,7 +55,6 @@ public enum ChannelBinding {
return valueOf(
CaseFormat.LOWER_HYPHEN.converterTo(CaseFormat.UPPER_UNDERSCORE).convert(type));
} catch (final IllegalArgumentException e) {
Log.d(Config.LOGTAG, type + " is not a known channel binding");
return null;
}
}

View file

@ -1,14 +1,12 @@
package im.conversations.android.xmpp.sasl;
import android.util.Base64;
import android.util.Log;
import com.google.common.base.MoreObjects;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;
import com.google.common.hash.HashFunction;
import com.google.common.primitives.Bytes;
import eu.siacs.conversations.Config;
import im.conversations.android.database.model.Account;
import im.conversations.android.database.model.Credential;
import im.conversations.android.tls.SSLSockets;
@ -18,9 +16,13 @@ import java.util.Collection;
import java.util.List;
import javax.net.ssl.SSLSocket;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class HashedToken extends SaslMechanism implements ChannelBindingMechanism {
private static final Logger LOGGER = LoggerFactory.getLogger(HashedToken.class);
private static final String PREFIX = "HT";
private static final List<String> HASH_FUNCTIONS = Arrays.asList("SHA-512", "SHA-256");
@ -65,12 +67,7 @@ public abstract class HashedToken extends SaslMechanism implements ChannelBindin
try {
return ChannelBindingMechanism.getChannelBindingData(sslSocket, this.channelBinding);
} catch (final AuthenticationException e) {
Log.e(
Config.LOGTAG,
account.address
+ ": unable to retrieve channel binding data for "
+ getMechanism(),
e);
LOGGER.error("Could not retrieve channel binding data for {}", getMechanism(), e);
return new byte[0];
}
}

View file

@ -1,10 +1,8 @@
package im.conversations.android.xmpp.sasl;
import android.util.Log;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.Collections2;
import eu.siacs.conversations.Config;
import im.conversations.android.database.model.Account;
import im.conversations.android.database.model.Credential;
import im.conversations.android.tls.SSLSockets;
@ -13,9 +11,13 @@ import im.conversations.android.xml.Namespace;
import java.util.Collection;
import java.util.Collections;
import javax.net.ssl.SSLSocket;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class SaslMechanism {
private static final Logger LOGGER = LoggerFactory.getLogger(SaslMechanism.class);
protected final Account account;
protected final Credential credential;
@ -216,9 +218,7 @@ public abstract class SaslMechanism {
if (ChannelBinding.isAvailable(cb, sslVersion)) {
return mechanism;
} else {
Log.d(
Config.LOGTAG,
"pinned channel binding method " + cb + " no longer available");
LOGGER.warn("Pinned channel binding method {} no longer available", cb);
return null;
}
} else {