diff options
author | Martin Hibdon <mhibdon@google.com> | 2014-08-28 14:33:13 -0700 |
---|---|---|
committer | Martin Hibdon <mhibdon@google.com> | 2014-08-28 15:27:42 -0700 |
commit | 3c193c425ff383dbc94514d055ae6778821d8471 (patch) | |
tree | eb405f4202a780d58dbee0a961a9e79cdf9fe79f | |
parent | a099d7183d4f070f8f9563292afa08c7b8f0d6fa (diff) | |
download | android_packages_apps_Exchange-3c193c425ff383dbc94514d055ae6778821d8471.tar.gz android_packages_apps_Exchange-3c193c425ff383dbc94514d055ae6778821d8471.tar.bz2 android_packages_apps_Exchange-3c193c425ff383dbc94514d055ae6778821d8471.zip |
Hook up exchange logging to the debug screen
Change-Id: Ia4d5a1f0112762444a57f3b4e47f5771331960ee
-rw-r--r-- | src/com/android/exchange/Eas.java | 17 | ||||
-rw-r--r-- | src/com/android/exchange/adapter/Parser.java | 24 | ||||
-rw-r--r-- | src/com/android/exchange/adapter/Serializer.java | 9 | ||||
-rw-r--r-- | src/com/android/exchange/service/EasService.java | 31 | ||||
-rw-r--r-- | tests/src/com/android/exchange/adapter/ParserTest.java | 4 |
5 files changed, 38 insertions, 47 deletions
diff --git a/src/com/android/exchange/Eas.java b/src/com/android/exchange/Eas.java index 325d15ea..2b5a0525 100644 --- a/src/com/android/exchange/Eas.java +++ b/src/com/android/exchange/Eas.java @@ -35,13 +35,10 @@ public class Eas { public static final String LOG_TAG = "Exchange"; // For debugging - public static boolean WAIT_DEBUG = false; // DO NOT CHECK IN WITH THIS SET TO TRUE public static boolean DEBUG = false; // DO NOT CHECK IN WITH THIS SET TO TRUE // The following two are for user logging (the second providing more detail) public static boolean USER_LOG = false; // DO NOT CHECK IN WITH THIS SET TO TRUE - public static boolean PARSER_LOG = false; // DO NOT CHECK IN WITH THIS SET TO TRUE - public static boolean FILE_LOG = false; // DO NOT CHECK IN WITH THIS SET TO TRUE public static final String CLIENT_VERSION = "EAS-2.0"; public static final String ACCOUNT_MAILBOX_PREFIX = "__eas"; @@ -129,20 +126,6 @@ public class Eas { public static final int EXCHANGE_ERROR_NOTIFICATION = 0x10; - public static void setUserDebug(int state) { - // DEBUG takes precedence and is never true in a user build - if (!DEBUG) { - USER_LOG = (state & EmailServiceProxy.DEBUG_BIT) != 0; - PARSER_LOG = (state & EmailServiceProxy.DEBUG_EXCHANGE_BIT) != 0; - FILE_LOG = (state & EmailServiceProxy.DEBUG_FILE_BIT) != 0; - if (FILE_LOG || PARSER_LOG) { - USER_LOG = true; - } - LogUtils.d("Eas Debug", "Logging: " + (USER_LOG ? "User " : "") + - (PARSER_LOG ? "Parser " : "") + (FILE_LOG ? "File" : "")); - } - } - static public Double getProtocolVersionDouble(String version) { if (SUPPORTED_PROTOCOL_EX2003.equals(version)) { return SUPPORTED_PROTOCOL_EX2003_DOUBLE; diff --git a/src/com/android/exchange/adapter/Parser.java b/src/com/android/exchange/adapter/Parser.java index 6e7e7d83..7c57f17e 100644 --- a/src/com/android/exchange/adapter/Parser.java +++ b/src/com/android/exchange/adapter/Parser.java @@ -21,6 +21,7 @@ import android.content.Context; import com.android.exchange.Eas; import com.android.exchange.EasException; +import com.android.exchange.service.EasService; import com.android.exchange.utility.FileLogger; import com.android.mail.utils.LogUtils; import com.google.common.annotations.VisibleForTesting; @@ -68,7 +69,6 @@ public abstract class Parser { private static final int NOT_ENDED = Integer.MIN_VALUE; private static final int EOF_BYTE = -1; - private boolean logging = false; private boolean capture = false; private ArrayList<Integer> captureArray; @@ -76,9 +76,6 @@ public abstract class Parser { // The input stream for this parser private InputStream in; - // The current tag depth - private int depth; - // The stack of names of tags being processed; used when debug = true private String[] nameArray = new String[32]; @@ -181,7 +178,6 @@ public abstract class Parser { public Parser(final InputStream in) throws IOException { setInput(in, true); - logging = Eas.PARSER_LOG; } /** @@ -191,18 +187,6 @@ public abstract class Parser { */ public Parser(final Parser parser) throws IOException { setInput(parser.in, false); - logging = Eas.PARSER_LOG; - } - - /** - * Set the debug state of the parser. When debugging is on, every token is logged (LogUtils.v) - * to the console. - * - * @param val the desired state for debug output - */ - @VisibleForTesting - public void setDebug(final boolean val) { - logging = val; } protected InputStream getInput() { @@ -406,7 +390,7 @@ public abstract class Parser { } void log(final String str) { - if (!logging) { + if (!EasService.getProtocolLogging()) { return; } final String logStr; @@ -419,8 +403,8 @@ public abstract class Parser { final char [] charArray = new char[startTagArray.size() * 2]; Arrays.fill(charArray, ' '); final String indent = new String(charArray); - LogUtils.v(LOG_TAG, "%s", indent + logStr); - if (Eas.FILE_LOG) { + LogUtils.d(LOG_TAG, "%s", indent + logStr); + if (EasService.getFileLogging()) { FileLogger.log(LOG_TAG, logStr); } } diff --git a/src/com/android/exchange/adapter/Serializer.java b/src/com/android/exchange/adapter/Serializer.java index d28e4c2c..7f696edd 100644 --- a/src/com/android/exchange/adapter/Serializer.java +++ b/src/com/android/exchange/adapter/Serializer.java @@ -27,6 +27,7 @@ import android.content.ContentValues; import android.text.TextUtils; import com.android.exchange.Eas; +import com.android.exchange.service.EasService; import com.android.exchange.utility.FileLogger; import com.android.mail.utils.LogUtils; import com.google.common.annotations.VisibleForTesting; @@ -48,7 +49,6 @@ public class Serializer { private int mPendingTag = NOT_PENDING; private final Deque<String> mNameStack = new ArrayDeque<String>(); private int mTagPage = 0; - private final boolean mLogging = LogUtils.isLoggable(TAG, LogUtils.VERBOSE); public Serializer() throws IOException { this(new ByteArrayOutputStream(), true); @@ -67,7 +67,6 @@ public class Serializer { * Base constructor * @param outputStream the stream we're serializing to * @param startDocument whether or not to start a document - * @param _logging whether or not to log our output * @throws IOException */ public Serializer(final OutputStream outputStream, final boolean startDocument) @@ -82,7 +81,7 @@ public class Serializer { } void log(final String str) { - if (!mLogging) { + if (!EasService.getProtocolLogging()) { return; } final String logStr; @@ -95,8 +94,8 @@ public class Serializer { final char [] charArray = new char[mNameStack.size() * 2]; Arrays.fill(charArray, ' '); final String indent = new String(charArray); - LogUtils.v(TAG, "%s%s", indent, logStr); - if (Eas.FILE_LOG) { + LogUtils.d(TAG, "%s%s", indent, logStr); + if (EasService.getFileLogging()) { FileLogger.log(TAG, logStr); } } diff --git a/src/com/android/exchange/service/EasService.java b/src/com/android/exchange/service/EasService.java index 3f840984..b2964e6d 100644 --- a/src/com/android/exchange/service/EasService.java +++ b/src/com/android/exchange/service/EasService.java @@ -54,6 +54,7 @@ import com.android.exchange.eas.EasSyncCalendar; import com.android.exchange.eas.EasSyncContacts; import com.android.exchange.provider.GalResult; import com.android.mail.utils.LogUtils; +import com.google.common.annotations.VisibleForTesting; import java.util.HashSet; import java.util.Set; @@ -77,7 +78,8 @@ public class EasService extends Service { /** Bookkeeping for ping tasks & sync threads management. */ private final PingSyncSynchronizer mSynchronizer; - private boolean mDebuggingEnabled; + private static boolean sProtocolLogging; + private static boolean sFileLogging; /** * Implementation of the IEmailService interface. @@ -210,8 +212,9 @@ public class EasService extends Service { public void setLogging(final int flags) { // TODO: This isn't persisted. If Exchange goes down and restarts, debugging will // be turned off. - mDebuggingEnabled = ((flags & EmailServiceProxy.DEBUG_EXCHANGE_BIT) != 0); - LogUtils.d(TAG, "IEmailService.setLogging"); + sProtocolLogging = ((flags & EmailServiceProxy.DEBUG_EXCHANGE_BIT) != 0); + sFileLogging = ((flags & EmailServiceProxy.DEBUG_FILE_BIT) != 0); + LogUtils.d(TAG, "IEmailService.setLogging %d", flags); } @Override @@ -277,7 +280,8 @@ public class EasService extends Service { public EasService() { super(); mSynchronizer = new PingSyncSynchronizer(this); - mDebuggingEnabled = false; + sProtocolLogging = false; + sFileLogging = false; } @Override @@ -492,4 +496,23 @@ public class EasService extends Service { } return authsToSync; } + + @VisibleForTesting + public static void setProtocolLogging(final boolean val) { + sProtocolLogging = val; + } + + @VisibleForTesting + public static void setFileLogging(final boolean val) { + sFileLogging = val; + } + + public static boolean getProtocolLogging() { + return sProtocolLogging; + } + + public static boolean getFileLogging() { + return sFileLogging; + } + } diff --git a/tests/src/com/android/exchange/adapter/ParserTest.java b/tests/src/com/android/exchange/adapter/ParserTest.java index 8b36433d..d39e4067 100644 --- a/tests/src/com/android/exchange/adapter/ParserTest.java +++ b/tests/src/com/android/exchange/adapter/ParserTest.java @@ -20,6 +20,8 @@ import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.SmallTest; import android.text.TextUtils; +import com.android.exchange.service.EasService; + import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.IOException; @@ -34,7 +36,7 @@ public class ParserTest extends AndroidTestCase { public TestParser(InputStream in, Object[] expectedData) throws IOException{ super(in); - setDebug(true); + EasService.setProtocolLogging(true); mExpectedData = expectedData == null ? null : new ArrayDeque<Object>(Arrays.asList(expectedData)); } |