Added the strict mode
added strict mode, which will be enabled only for debug builds. Signed-off-by: DevarshVasani <vasanidevarsh@gmail.com>
This commit is contained in:
parent
787c6b6c00
commit
1e7e860213
1 changed files with 47 additions and 0 deletions
|
@ -6,9 +6,11 @@ import android.app.Activity;
|
|||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.StrictMode;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -142,6 +144,14 @@ public class MwmApplication extends Application implements Application.ActivityL
|
|||
public void onCreate()
|
||||
{
|
||||
super.onCreate();
|
||||
|
||||
//this will enable the strict mode only when the application is in debug mode
|
||||
if (BuildConfig.DEBUG)
|
||||
{
|
||||
enableStrictMode();
|
||||
}
|
||||
|
||||
|
||||
Logger.i(TAG, "Initializing application");
|
||||
LogsManager.INSTANCE.initFileLogging(this);
|
||||
|
||||
|
@ -217,6 +227,43 @@ public class MwmApplication extends Application implements Application.ActivityL
|
|||
Logger.i(TAG, "Platform initialized");
|
||||
}
|
||||
|
||||
private void enableStrictMode()
|
||||
{
|
||||
StrictMode.ThreadPolicy.Builder threadPolicyBuilder = new StrictMode.ThreadPolicy.Builder()
|
||||
.detectDiskReads()
|
||||
.detectDiskWrites()
|
||||
.detectNetwork() // or .detectAll() for all detectable problems
|
||||
.penaltyLog();
|
||||
|
||||
threadPolicyBuilder.detectCustomSlowCalls();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||
{
|
||||
threadPolicyBuilder.detectResourceMismatches();
|
||||
}
|
||||
|
||||
StrictMode.setThreadPolicy(threadPolicyBuilder.build());
|
||||
|
||||
StrictMode.VmPolicy.Builder vmPolicyBuilder = new StrictMode.VmPolicy.Builder()
|
||||
.detectLeakedSqlLiteObjects()
|
||||
.detectLeakedClosableObjects()
|
||||
.penaltyLog();
|
||||
|
||||
vmPolicyBuilder.detectFileUriExposure();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||
{
|
||||
vmPolicyBuilder.detectCleartextNetwork();
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM)
|
||||
{
|
||||
vmPolicyBuilder.detectUnsafeIntentLaunch();
|
||||
}
|
||||
|
||||
StrictMode.setVmPolicy(vmPolicyBuilder.build());
|
||||
}
|
||||
|
||||
private void createPlatformDirectories(@NonNull String writablePath,
|
||||
@NonNull String privatePath,
|
||||
@NonNull String tempPath) throws IOException
|
||||
|
|
Reference in a new issue