mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Make strict mode warnings configurable
This commit is contained in:
@@ -6,6 +6,8 @@ import android.app.Application;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.os.Build.VERSION_CODES;
|
||||||
import android.os.StrictMode;
|
import android.os.StrictMode;
|
||||||
import android.os.StrictMode.ThreadPolicy;
|
import android.os.StrictMode.ThreadPolicy;
|
||||||
import android.os.StrictMode.VmPolicy;
|
import android.os.StrictMode.VmPolicy;
|
||||||
@@ -120,12 +122,62 @@ public class BriarApplicationImpl extends Application
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void enableStrictMode() {
|
private void enableStrictMode() {
|
||||||
|
int targetSdk = Build.VERSION.SDK_INT;
|
||||||
|
|
||||||
ThreadPolicy.Builder threadPolicy = new ThreadPolicy.Builder();
|
ThreadPolicy.Builder threadPolicy = new ThreadPolicy.Builder();
|
||||||
threadPolicy.detectAll();
|
|
||||||
|
// pulled in from threadPolicy.detectAll();
|
||||||
|
threadPolicy.detectDiskReads();
|
||||||
|
threadPolicy.detectDiskWrites();
|
||||||
|
threadPolicy.detectNetwork();
|
||||||
|
|
||||||
|
if (targetSdk >= VERSION_CODES.HONEYCOMB) {
|
||||||
|
threadPolicy.detectCustomSlowCalls();
|
||||||
|
}
|
||||||
|
if (targetSdk >= VERSION_CODES.M) {
|
||||||
|
threadPolicy.detectResourceMismatches();
|
||||||
|
}
|
||||||
|
if (targetSdk >= VERSION_CODES.O) {
|
||||||
|
threadPolicy.detectUnbufferedIo();
|
||||||
|
}
|
||||||
|
// -- end detectAll()
|
||||||
|
|
||||||
threadPolicy.penaltyLog();
|
threadPolicy.penaltyLog();
|
||||||
StrictMode.setThreadPolicy(threadPolicy.build());
|
StrictMode.setThreadPolicy(threadPolicy.build());
|
||||||
|
|
||||||
VmPolicy.Builder vmPolicy = new VmPolicy.Builder();
|
VmPolicy.Builder vmPolicy = new VmPolicy.Builder();
|
||||||
vmPolicy.detectAll();
|
|
||||||
|
// pulled in from vmPolicy.detectAll();
|
||||||
|
vmPolicy.detectLeakedSqlLiteObjects();
|
||||||
|
if (targetSdk >= VERSION_CODES.HONEYCOMB) {
|
||||||
|
vmPolicy.detectActivityLeaks();
|
||||||
|
vmPolicy.detectLeakedClosableObjects();
|
||||||
|
}
|
||||||
|
if (targetSdk >= VERSION_CODES.JELLY_BEAN) {
|
||||||
|
vmPolicy.detectLeakedRegistrationObjects();
|
||||||
|
}
|
||||||
|
if (targetSdk >= VERSION_CODES.JELLY_BEAN_MR2) {
|
||||||
|
vmPolicy.detectFileUriExposure();
|
||||||
|
}
|
||||||
|
if (targetSdk >= VERSION_CODES.M) {
|
||||||
|
vmPolicy.detectCleartextNetwork();
|
||||||
|
}
|
||||||
|
if (targetSdk >= VERSION_CODES.O) {
|
||||||
|
vmPolicy.detectContentUriWithoutPermission();
|
||||||
|
// do not detect untagged sockets
|
||||||
|
// vmPolicy.detectUntaggedSockets();
|
||||||
|
}
|
||||||
|
if (targetSdk >= VERSION_CODES.Q) {
|
||||||
|
vmPolicy.detectCredentialProtectedWhileLocked();
|
||||||
|
}
|
||||||
|
if (targetSdk >= VERSION_CODES.R) {
|
||||||
|
// for some reason this won't compile
|
||||||
|
// vmPolicy.detectIncorrectContextUse();
|
||||||
|
}
|
||||||
|
// -- end detectAll()
|
||||||
|
|
||||||
|
// TODO: add detectUnsafeIntentLaunch() after upgrading to API level 31
|
||||||
|
|
||||||
vmPolicy.penaltyLog();
|
vmPolicy.penaltyLog();
|
||||||
StrictMode.setVmPolicy(vmPolicy.build());
|
StrictMode.setVmPolicy(vmPolicy.build());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user