Add strict mode preference

pull/645/head
Alex Baker 6 years ago
parent b882e5d690
commit 2a54775927

@ -9,6 +9,7 @@ import com.facebook.stetho.timber.StethoTree;
import com.squareup.leakcanary.LeakCanary;
import org.tasks.injection.ForApplication;
import org.tasks.preferences.Preferences;
import javax.inject.Inject;
@ -16,10 +17,12 @@ import timber.log.Timber;
public class BuildSetup {
private final Context context;
private final Preferences preferences;
@Inject
public BuildSetup(@ForApplication Context context) {
public BuildSetup(@ForApplication Context context, Preferences preferences) {
this.context = context;
this.preferences = preferences;
}
public boolean setup() {
@ -31,17 +34,19 @@ public class BuildSetup {
return false;
}
LeakCanary.install(application);
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork()
.penaltyLog()
.build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.penaltyLog()
.build());
if (preferences.getBoolean(R.string.p_strict_mode, false)) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork()
.penaltyLog()
.build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.penaltyLog()
.build());
}
return true;
}
}

@ -283,10 +283,12 @@
<string name="sku_dashclock">dashclock</string>
<string name="debug_unlock_purchases">Unlock purchases</string>
<string name="debug_consume_purchases">Consume purchases</string>
<string name="debug_strict_mode">Strict mode</string>
<string name="debug">Debug</string>
<string name="p_start_of_week">start_of_week</string>
<string name="p_use_native_datetime_pickers">use_native_datetime_pickers</string>
<string name="gtask_background_sync">gtask_background_sync</string>
<string name="p_bundle_notifications">bundle_notifications</string>
<string name="p_strict_mode">strict_mode</string>
</resources>

@ -12,6 +12,10 @@
android:title="@string/debug_consume_purchases"
android:key="@string/debug_consume_purchases" />
<CheckBoxPreference
android:title="@string/debug_strict_mode"
android:key="@string/p_strict_mode" />
</PreferenceCategory>
</PreferenceScreen>
Loading…
Cancel
Save