151c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdonpackage com.android.email;
251c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon
351c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdonimport android.content.Context;
451c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon
551c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdonimport com.android.email.service.EmailServiceUtils;
651c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdonimport com.android.emailcommon.service.EmailServiceProxy;
751c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdonimport com.android.emailcommon.utility.Utility;
851c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdonimport com.android.mail.utils.LogTag;
951c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon
1051c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdonpublic class DebugUtils {
1151c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon    public static final String LOG_TAG = LogTag.getLogTag();
1251c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon
1351c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon    public static boolean DEBUG;
1451c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon    public static boolean DEBUG_EXCHANGE;
1551c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon    public static boolean DEBUG_FILE;
1651c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon
1751c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon    public static void init(final Context context) {
1851c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon        final Preferences prefs = Preferences.getPreferences(context);
1951c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon        DEBUG = prefs.getEnableDebugLogging();
2051c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon        DEBUG_EXCHANGE = prefs.getEnableExchangeLogging();
2151c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon        DEBUG_FILE = prefs.getEnableExchangeFileLogging();
2251c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon
2351c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon        // Enable logging in the EAS service, so it starts up as early as possible.
2451c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon        updateLoggingFlags(context);
2551c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon        enableStrictMode(prefs.getEnableStrictMode());
2651c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon    }
2751c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon
2851c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon    /**
2951c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon     * Load enabled debug flags from the preferences and update the EAS debug flag.
3051c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon     */
3151c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon    public static void updateLoggingFlags(Context context) {
3251c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon        Preferences prefs = Preferences.getPreferences(context);
3351c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon        int debugLogging = prefs.getEnableDebugLogging() ? EmailServiceProxy.DEBUG_BIT : 0;
3451c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon        int exchangeLogging =
3551c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon                prefs.getEnableExchangeLogging() ? EmailServiceProxy.DEBUG_EXCHANGE_BIT: 0;
3651c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon        int fileLogging =
3751c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon                prefs.getEnableExchangeFileLogging() ? EmailServiceProxy.DEBUG_FILE_BIT : 0;
3851c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon        int enableStrictMode =
3951c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon                prefs.getEnableStrictMode() ? EmailServiceProxy.DEBUG_ENABLE_STRICT_MODE : 0;
4051c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon        int debugBits = debugLogging | exchangeLogging | fileLogging | enableStrictMode;
4151c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon        EmailServiceUtils.setRemoteServicesLogging(context, debugBits);
4251c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon    }
4351c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon
4451c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon    public static void  enableStrictMode(final boolean enable) {
4551c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon        Utility.enableStrictMode(enable);
4651c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon    }
4751c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon
4851c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon}
49