Skip to content

Commit b4f102b

Browse files
committed
Let debugging be controlled by setprop.
Use isLoggable.
1 parent 840ffa0 commit b4f102b

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

Diff for: .classpath

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<classpathentry kind="lib" path="libs/jsoup-1.5.2.jar"/>
88
<classpathentry kind="lib" path="libs/commons-codec.jar"/>
99
<classpathentry kind="lib" path="libs/guava-r09.jar"/>
10-
<classpathentry kind="lib" path="libs/asmack-android-7.jar"/>
10+
<classpathentry kind="lib" path="libs/asmack-android-7.jar" sourcepath="asmack/build/src/trunk"/>
1111
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
1212
<classpathentry kind="output" path="bin/classes"/>
1313
</classpath>

Diff for: src/info/guardianproject/otr/OtrDebugLogger.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class OtrDebugLogger {
99
public static boolean errorLog = true;
1010

1111
public static void log(String msg) {
12-
if (debugLog)
12+
if (debugLog && Log.isLoggable(TAG, Log.DEBUG))
1313
Log.d(TAG, msg);
1414
}
1515

Diff for: src/info/guardianproject/otr/app/im/plugin/xmpp/XmppConnection.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@
4141

4242
import org.apache.harmony.javax.security.auth.callback.Callback;
4343
import org.apache.harmony.javax.security.auth.callback.CallbackHandler;
44-
import org.jivesoftware.smack.Connection;
4544
import org.jivesoftware.smack.ConnectionConfiguration;
4645
import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode;
47-
import org.jivesoftware.smack.ConnectionCreationListener;
4846
import org.jivesoftware.smack.ConnectionListener;
4947
import org.jivesoftware.smack.PacketCollector;
5048
import org.jivesoftware.smack.PacketListener;
@@ -77,7 +75,7 @@
7775

7876
public class XmppConnection extends ImConnection implements CallbackHandler {
7977

80-
final static String TAG = "Gibberbot.XmppConnection";
78+
final static String TAG = "GB.XmppConnection";
8179
private final static boolean DEBUG_ENABLED = false;
8280

8381
private XmppContactList mContactListManager;
@@ -541,6 +539,7 @@ private void initConnection(String userName, final String password,
541539

542540
@Override
543541
public void processPacket(Packet packet) {
542+
debug(TAG, "receive message");
544543
org.jivesoftware.smack.packet.Message smackMessage = (org.jivesoftware.smack.packet.Message) packet;
545544
String address = parseAddressBase(smackMessage.getFrom());
546545
ChatSession session = findOrCreateSession(address);
@@ -1602,7 +1601,9 @@ protected void setState(int state, ImErrorInfo error) {
16021601
}
16031602

16041603
public void debug(String tag, String msg) {
1605-
//Log.d(tag, "" + mGlobalId + " : " + msg);
1604+
if (Log.isLoggable(TAG, Log.DEBUG)) {
1605+
Log.d(tag, "" + mGlobalId + " : " + msg);
1606+
}
16061607
}
16071608

16081609
@Override

Diff for: src/info/guardianproject/otr/app/im/plugin/xmpp/XmppStreamHandler.java

+27-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.Map;
88

99
import org.jivesoftware.smack.ConnectionListener;
10+
import org.jivesoftware.smack.PacketInterceptor;
1011
import org.jivesoftware.smack.PacketListener;
1112
import org.jivesoftware.smack.filter.PacketFilter;
1213
import org.jivesoftware.smack.packet.Packet;
@@ -27,6 +28,7 @@ public class XmppStreamHandler {
2728
private long previousIncomingStanzaCount = -1;
2829
private String sessionId;
2930
private long incomingStanzaCount = 0;
31+
private long outgoingStanzaCount = 0;
3032

3133
public XmppStreamHandler(MyXMPPConnection connection) {
3234
mConnection = connection;
@@ -112,10 +114,23 @@ public void connectionClosed() {
112114
}
113115
});
114116

117+
mConnection.addPacketInterceptor(new PacketInterceptor() {
118+
public void interceptPacket(Packet packet) {
119+
if (isSmEnabled)
120+
outgoingStanzaCount++;
121+
trace("send " + outgoingStanzaCount + " : " + packet.toXML());
122+
}
123+
}, new PacketFilter() {
124+
public boolean accept(Packet packet) {
125+
return true;
126+
}
127+
});
128+
115129
mConnection.addPacketListener(new PacketListener() {
116130
public void processPacket(Packet packet) {
117-
incomingStanzaCount++;
118-
//debug("" + incomingStanzaCount + " : " + packet.toXML());
131+
if (isSmEnabled)
132+
incomingStanzaCount++;
133+
trace("recv " + incomingStanzaCount + " : " + packet.toXML());
119134
if (packet instanceof StreamHandlingPacket) {
120135
StreamHandlingPacket shPacket = (StreamHandlingPacket) packet;
121136
String name = shPacket.getElementName();
@@ -132,6 +147,7 @@ public void processPacket(Packet packet) {
132147
} else if ("enabled".equals(name)) {
133148
debug("sm enabled " + sessionId);
134149
incomingStanzaCount = 0;
150+
outgoingStanzaCount = 0;
135151
isSmEnabled = true;
136152
mConnection.getRoster().setOfflineOnError(false);
137153
String resume = shPacket.getAttribute("resume");
@@ -176,7 +192,15 @@ public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
176192
}
177193

178194
private void debug(String message) {
179-
//Log.d(XmppConnection.TAG, message);
195+
if (Log.isLoggable(XmppConnection.TAG, Log.DEBUG)) {
196+
Log.d(XmppConnection.TAG, message);
197+
}
198+
}
199+
200+
private void trace(String message) {
201+
if (Log.isLoggable(XmppConnection.TAG, Log.VERBOSE)) {
202+
Log.v(XmppConnection.TAG, message);
203+
}
180204
}
181205

182206
static class StreamHandlingPacket extends UnknownPacket {

0 commit comments

Comments
 (0)