Skip to content

Commit

Permalink
Update sample
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiryl Rozau committed Mar 9, 2019
1 parent 7783d1d commit 66ed0f0
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 37 deletions.
5 changes: 4 additions & 1 deletion sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
compileSdkVersion rootProject.ext.compileSdkVersion
Expand Down Expand Up @@ -26,9 +27,11 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

sourceSets.main.java.srcDirs += 'src/main/kotlin'
}

dependencies {
implementation "androidx.appcompat:appcompat:$androidXAppCompatVersion"
implementation project(':strict-mode-compat')
implementation project(':strict-mode-compat-kotlin')
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,55 +10,24 @@

public class SampleApplication extends Application {

private static final String TAG = "Sample";

@Override
public void onCreate() {
super.onCreate();
if (BuildConfig.DEVELOPER_MODE) {
StrictMode.ThreadPolicy threadPolicy = new StrictModeCompat.ThreadPolicy.Builder()
.detectAll()
.detectCustomSlowCalls()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork()
.detectResourceMismatches()
.detectUnbufferedIo()
.penaltyDeath()
.penaltyDeathOnNetwork()
.penaltyDialog()
.penaltyDropBox()
.penaltyFlashScreen()
.penaltyListener(Executors.newSingleThreadExecutor(), violation -> Log.e(TAG, "", violation))
.detectCustomSlowCalls()
.detectUnbufferedIo() // Available only on Android 8.0+
.penaltyLog()
.permitAll()
.permitCustomSlowCalls()
.permitDiskReads()
.permitDiskWrites()
.permitNetwork()
.permitResourceMismatches()
.permitUnbufferedIo()
.build();

StrictMode.VmPolicy vmPolicy = new StrictModeCompat.VmPolicy.Builder()
.detectActivityLeaks()
.detectAll()
.detectCleartextNetwork()
.detectContentUriWithoutPermission()
.detectFileUriExposure()
.detectLeakedClosableObjects()
.detectLeakedRegistrationObjects()
.detectLeakedSqlLiteObjects()
.detectNonSdkApiUsage()
.detectUntaggedSockets()
.penaltyDeath()
.penaltyDeathOnCleartextNetwork()
.penaltyDeathOnFileUriExposure()
.penaltyDropBox()
.penaltyListener(Executors.newSingleThreadExecutor(), violation -> Log.e(TAG, "", violation))
.detectCleartextNetwork()
.detectUntaggedSockets() // Available only on Android 8.0+
.detectContentUriWithoutPermission() // Available only on Android 8.0+
.penaltyLog()
.permitNonSdkApiUsage()
.setClassInstanceLimit(Object.class, 100)
.build();

StrictModeCompat.setPolicies(threadPolicy, vmPolicy);
Expand Down
42 changes: 42 additions & 0 deletions sample/src/main/kotlin/SampleApplicationKt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import android.annotation.SuppressLint
import android.app.Application
import android.os.StrictMode
import android.util.Log

import com.kirillr.application.BuildConfig
import com.kirillr.strictmodehelper.StrictModeCompat
import com.kirillr.strictmodehelper.kotlin.dsl.initStrictMode

import java.util.concurrent.Executors

@SuppressLint("Registered")
class SampleApplicationKt : Application() {

override fun onCreate() {
super.onCreate()
initStrictMode(enable = BuildConfig.DEVELOPER_MODE, enableDefaults = false) {
threadPolicy {
resourceMismatches = true
customSlowCalls = true
unbufferedIo = true

penalty {
log = true
}
}

vmPolicy {
fileUriExposure = true
leakedRegistrationObjects = true
cleartextNetwork = true
cleartextNetwork = true
untaggedSockets = true
contentUriWithoutPermission = true

penalty {
log = true
}
}
}
}
}

0 comments on commit 66ed0f0

Please sign in to comment.