diff --git a/emailcommon/src/com/android/emailcommon/service/EmailServiceProxy.java b/emailcommon/src/com/android/emailcommon/service/EmailServiceProxy.java index ebe3b68a4..af65d830f 100644 --- a/emailcommon/src/com/android/emailcommon/service/EmailServiceProxy.java +++ b/emailcommon/src/com/android/emailcommon/service/EmailServiceProxy.java @@ -68,6 +68,8 @@ public class EmailServiceProxy extends ServiceProxy implements IEmailService { public static final int DEBUG_VERBOSE_BIT = 2; // File (SD card) logging public static final int DEBUG_FILE_BIT = 4; + // Enable strict mode + public static final int DEBUG_ENABLE_STRICT_MODE = 8; // The first two constructors are used with local services that can be referenced by class public EmailServiceProxy(Context _context, Class _class) { diff --git a/emailcommon/src/com/android/emailcommon/utility/Utility.java b/emailcommon/src/com/android/emailcommon/utility/Utility.java index f3dc599c2..f89b6082f 100644 --- a/emailcommon/src/com/android/emailcommon/utility/Utility.java +++ b/emailcommon/src/com/android/emailcommon/utility/Utility.java @@ -44,6 +44,7 @@ import android.os.Environment; import android.os.Handler; import android.os.Parcel; import android.os.Parcelable; +import android.os.StrictMode; import android.provider.OpenableColumns; import android.text.Spannable; import android.text.SpannableString; @@ -1128,4 +1129,13 @@ public class Utility { public static boolean areStringsEqual(String s1, String s2) { return (s1 != null && s1.equals(s2)) || (s1 == null && s2 == null); } + + public static void enableStrictMode(boolean enabled) { + StrictMode.setThreadPolicy(enabled + ? new StrictMode.ThreadPolicy.Builder().detectAll().build() + : StrictMode.ThreadPolicy.LAX); + StrictMode.setVmPolicy(enabled + ? new StrictMode.VmPolicy.Builder().detectAll().build() + : StrictMode.VmPolicy.LAX); + } } diff --git a/res/layout/debug.xml b/res/layout/debug.xml index a14234905..6312ae2c0 100644 --- a/res/layout/debug.xml +++ b/res/layout/debug.xml @@ -63,4 +63,10 @@ android:layout_height="wrap_content" android:text="@string/debug_force_one_minute_refresh_label" /> + diff --git a/res/values/strings.xml b/res/values/strings.xml index c0420209d..83f03413a 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -262,6 +262,9 @@ Force 1-minute refresh for POP/IMAP + + + Enable strict mode (with logging) Accounts diff --git a/src/com/android/email/Email.java b/src/com/android/email/Email.java index e12937d2e..c857ed2f8 100644 --- a/src/com/android/email/Email.java +++ b/src/com/android/email/Email.java @@ -197,6 +197,7 @@ public class Email extends Application { Preferences prefs = Preferences.getPreferences(this); DEBUG = prefs.getEnableDebugLogging(); sDebugInhibitGraphicsAcceleration = prefs.getInhibitGraphicsAcceleration(); + enableStrictMode(prefs.getEnableStrictMode()); TempDirectory.setTempDirectory(this); // Tie MailRefreshManager to the Controller. @@ -221,7 +222,9 @@ public class Email extends Application { prefs.getEnableExchangeLogging() ? EmailServiceProxy.DEBUG_VERBOSE_BIT : 0; int fileLogging = prefs.getEnableExchangeFileLogging() ? EmailServiceProxy.DEBUG_FILE_BIT : 0; - int debugBits = debugLogging | verboseLogging | fileLogging; + int enableStrictMode = + prefs.getEnableStrictMode() ? EmailServiceProxy.DEBUG_ENABLE_STRICT_MODE : 0; + int debugBits = debugLogging | verboseLogging | fileLogging | enableStrictMode; Controller.getInstance(context).serviceLogging(debugBits); } @@ -263,4 +266,8 @@ public class Email extends Application { public static String getMessageDecodeErrorString() { return sMessageDecodeErrorString != null ? sMessageDecodeErrorString : ""; } + + public static void enableStrictMode(boolean enabled) { + Utility.enableStrictMode(enabled); + } } diff --git a/src/com/android/email/Preferences.java b/src/com/android/email/Preferences.java index 942b8c851..675430167 100644 --- a/src/com/android/email/Preferences.java +++ b/src/com/android/email/Preferences.java @@ -38,6 +38,7 @@ public class Preferences { private static final String ENABLE_EXCHANGE_FILE_LOGGING = "enableExchangeFileLogging"; private static final String INHIBIT_GRAPHICS_ACCELERATION = "inhibitGraphicsAcceleration"; private static final String FORCE_ONE_MINUTE_REFRESH = "forceOneMinuteRefresh"; + private static final String ENABLE_STRICT_MODE = "enableStrictMode"; private static final String DEVICE_UID = "deviceUID"; private static final String ONE_TIME_INITIALIZATION_PROGRESS = "oneTimeInitializationProgress"; private static final String AUTO_ADVANCE_DIRECTION = "autoAdvance"; @@ -194,6 +195,14 @@ public class Preferences { return mSharedPreferences.getBoolean(FORCE_ONE_MINUTE_REFRESH, false); } + public void setEnableStrictMode(boolean value) { + mSharedPreferences.edit().putBoolean(ENABLE_STRICT_MODE, value).apply(); + } + + public boolean getEnableStrictMode() { + return mSharedPreferences.getBoolean(ENABLE_STRICT_MODE, false); + } + /** * Generate a new "device UID". This is local to Email app only, to prevent possibility * of correlation with any other user activities in any other apps. diff --git a/src/com/android/email/activity/setup/DebugFragment.java b/src/com/android/email/activity/setup/DebugFragment.java index 50a8cadd6..44bde9bac 100644 --- a/src/com/android/email/activity/setup/DebugFragment.java +++ b/src/com/android/email/activity/setup/DebugFragment.java @@ -44,6 +44,7 @@ public class DebugFragment extends Fragment implements OnCheckedChangeListener, private CheckBox mEnableExchangeFileLoggingView; private CheckBox mInhibitGraphicsAccelerationView; private CheckBox mForceOneMinuteRefreshView; + private CheckBox mEnableStrictModeView; private Preferences mPreferences; @@ -95,6 +96,11 @@ public class DebugFragment extends Fragment implements OnCheckedChangeListener, mForceOneMinuteRefreshView.setChecked(mPreferences.getForceOneMinuteRefresh()); mForceOneMinuteRefreshView.setOnCheckedChangeListener(this); + mEnableStrictModeView = (CheckBox) + view.findViewById(R.id.debug_enable_strict_mode); + mEnableStrictModeView.setChecked(mPreferences.getEnableStrictMode()); + mEnableStrictModeView.setOnCheckedChangeListener(this); + return view; } @@ -122,6 +128,10 @@ public class DebugFragment extends Fragment implements OnCheckedChangeListener, mPreferences.setForceOneMinuteRefresh(isChecked); MailService.actionReschedule(getActivity()); break; + case R.id.debug_enable_strict_mode: + mPreferences.setEnableStrictMode(isChecked); + Email.enableStrictMode(isChecked); + break; } Email.updateLoggingFlags(getActivity());