├── sample ├── .gitignore ├── src │ └── main │ │ ├── res │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── layout │ │ │ └── activity_main.xml │ │ └── values │ │ │ ├── strings.xml │ │ │ ├── colors.xml │ │ │ └── styles.xml │ │ ├── java │ │ └── com │ │ │ └── kirillr │ │ │ └── application │ │ │ ├── MainActivity.java │ │ │ └── SampleApplication.java │ │ ├── AndroidManifest.xml │ │ └── kotlin │ │ └── SampleApplicationKt.kt └── build.gradle ├── strict-mode-compat ├── .gitignore ├── build.gradle └── src │ └── main │ └── java │ └── com │ └── kirillr │ └── strictmodehelper │ ├── Utils.java │ └── StrictModeCompat.java ├── strict-mode-compat-kotlin ├── .gitignore ├── src │ └── main │ │ └── java │ │ └── com │ │ └── kirillr │ │ └── strictmodehelper │ │ └── kotlin │ │ ├── dsl │ │ ├── VmPolicyDsl.kt │ │ ├── StrictModeDsl.kt │ │ ├── ThreadPolicyDsl.kt │ │ ├── StrictModeConfig.kt │ │ ├── StringMode.kt │ │ ├── VmPolicyConfig.kt │ │ └── ThreadPolicyConfig.kt │ │ └── StrictModeCompat.kt └── build.gradle ├── scripts ├── check.sh └── publish.sh ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── CHANGELOG.md ├── publishing.gradle ├── gradlew.bat ├── README.md ├── gradlew └── LICENSE /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /strict-mode-compat/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /strict-mode-compat-kotlin/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /scripts/check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ./gradlew clean build check -PdisablePreDex 3 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':strict-mode-compat', ':sample', ':strict-mode-compat-kotlin' 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androidbroadcast/StrictModeCompat/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androidbroadcast/StrictModeCompat/HEAD/sample/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androidbroadcast/StrictModeCompat/HEAD/sample/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androidbroadcast/StrictModeCompat/HEAD/sample/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androidbroadcast/StrictModeCompat/HEAD/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androidbroadcast/StrictModeCompat/HEAD/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androidbroadcast/StrictModeCompat/HEAD/sample/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androidbroadcast/StrictModeCompat/HEAD/sample/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androidbroadcast/StrictModeCompat/HEAD/sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androidbroadcast/StrictModeCompat/HEAD/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androidbroadcast/StrictModeCompat/HEAD/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /scripts/publish.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ./gradlew :strict-mode-compat:assembleRelease :strict-mode-compat-kotlin:assembleRelease :strict-mode-compat:bintrayUpload :strict-mode-compat-kotlin:bintrayUpload -PdisablePreDex 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | build/ 3 | *.iml 4 | 5 | # Ignore Gradle GUI config 6 | gradle-app.setting 7 | 8 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 9 | # gradle/wrapper/gradle-wrapper.properties 10 | /.idea/ 11 | /local.properties 12 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | Application 19 | 20 | -------------------------------------------------------------------------------- /sample/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | #3F51B5 20 | #303F9F 21 | #FF4081 22 | 23 | -------------------------------------------------------------------------------- /strict-mode-compat-kotlin/src/main/java/com/kirillr/strictmodehelper/kotlin/dsl/VmPolicyDsl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2021 Kirill Rozov 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.kirillr.strictmodehelper.kotlin.dsl 18 | 19 | @DslMarker 20 | @Target(AnnotationTarget.TYPE, AnnotationTarget.CLASS) 21 | @Retention(AnnotationRetention.SOURCE) 22 | internal annotation class VmPolicyDsl 23 | -------------------------------------------------------------------------------- /strict-mode-compat-kotlin/src/main/java/com/kirillr/strictmodehelper/kotlin/dsl/StrictModeDsl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2021 Kirill Rozov 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.kirillr.strictmodehelper.kotlin.dsl 18 | 19 | @DslMarker 20 | @Target(AnnotationTarget.TYPE, AnnotationTarget.CLASS) 21 | @Retention(AnnotationRetention.SOURCE) 22 | internal annotation class StrictModeDsl 23 | -------------------------------------------------------------------------------- /strict-mode-compat-kotlin/src/main/java/com/kirillr/strictmodehelper/kotlin/dsl/ThreadPolicyDsl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2021 Kirill Rozov 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.kirillr.strictmodehelper.kotlin.dsl 18 | 19 | @DslMarker 20 | @Target(AnnotationTarget.TYPE, AnnotationTarget.CLASS) 21 | @Retention(AnnotationRetention.SOURCE) 22 | internal annotation class ThreadPolicyDsl 23 | -------------------------------------------------------------------------------- /strict-mode-compat-kotlin/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2021 Kirill Rozov 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | plugins { 18 | id 'java-library' 19 | id 'kotlin' 20 | } 21 | 22 | ext.artifactId = 'strict-mode-compat-ktx' 23 | apply from: rootProject.file('publishing.gradle') 24 | 25 | dependencies { 26 | api project(":strict-mode-compat") 27 | compileOnly androidJar 28 | } 29 | 30 | java { 31 | sourceCompatibility = JavaVersion.VERSION_1_7 32 | targetCompatibility = JavaVersion.VERSION_1_7 33 | } -------------------------------------------------------------------------------- /strict-mode-compat/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2021 Kirill Rozov 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | plugins { 18 | id 'java-library' 19 | } 20 | 21 | java { 22 | sourceCompatibility = JavaVersion.VERSION_1_7 23 | targetCompatibility = JavaVersion.VERSION_1_7 24 | } 25 | 26 | dependencies { 27 | implementation "androidx.annotation:annotation:$androidXAnnotationsVersion" 28 | compileOnly androidJar 29 | } 30 | 31 | ext.artifactId = 'strict-mode-compat' 32 | apply from: rootProject.file('publishing.gradle') -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | 19 | android.useAndroidX=true 20 | 21 | # Automatically convert third-party libraries to use AndroidX 22 | android.enableJetifier=false 23 | # Kotlin code style for this project: "official" or "obsolete": 24 | kotlin.code.style=official 25 | 26 | android.defaults.buildfeatures.aidl=false 27 | android.defaults.buildfeatures.buildconfig=false 28 | android.defaults.buildfeatures.dataBinding=false 29 | android.defaults.buildfeatures.renderscript=false 30 | android.defaults.buildfeatures.resvalues=false 31 | android.defaults.buildfeatures.shaders=false 32 | android.defaults.buildfeatures.viewbinding=false 33 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Change Log 2 | ========== 3 | 4 | Version 30.2.0 (2021-03-07) 5 | --------------------------------- 6 | - Minor improvements 7 | - Migration to Maven Central 8 | 9 | Version 30.0.0 (2020-06-27) 10 | --------------------------------- 11 | Add support Android 11 Stable SDK (Level 30) 12 | 13 | Version 29.0.0 (2019-06-25) 14 | --------------------------------- 15 | Update to Android Q Stable SDK (Level 29) 16 | 17 | Version 29.0.0-beta1 (2019-03-17) 18 | --------------------------------- 19 | Update to Android Q Beta 1 SDK (Level 29) 20 | 21 | Version 28.0.0 (2018-06-13) 22 | --------------------------- 23 | Update to Android P SDK (Level 28) 24 | Fix bugs with init Strict Mode 25 | Update library min sdk to Android SDK 14 26 | Update Android Support Library to 27.1.2 27 | Update Kotlin to 1.2.41 28 | 29 | Version 26.0.2 (2017-07-29) 30 | --------------------------- 31 | Adding Kotlin extensions library 32 | Minor improvements in base library 33 | 34 | Version 26.0.1 (2017-07-29) 35 | --------------------------- 36 | Update ot Android Support Library 26.0.0 37 | 38 | Version 26.0.0 (2017-06-18) 39 | --------------------------- 40 | Move to final version of Android O API 41 | 42 | Version 26.0.0-alpha1 (2017-04-23) 43 | ---------------------------------- 44 | Add updates of StrictMode in Android 0 Developer Preview 1 45 | 46 | Version 25.0.0 (2017-04-23) 47 | --------------------------- 48 | Initial Release 49 | -------------------------------------------------------------------------------- /sample/src/main/java/com/kirillr/application/MainActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2021 Kirill Rozov 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.kirillr.application; 18 | 19 | import android.os.Bundle; 20 | 21 | import com.kirillr.strictmodehelper.StrictModeCompat; 22 | 23 | import androidx.annotation.Nullable; 24 | import androidx.appcompat.app.AppCompatActivity; 25 | 26 | public class MainActivity extends AppCompatActivity { 27 | 28 | @Override 29 | protected void onCreate(Bundle savedInstanceState) { 30 | super.onCreate(savedInstanceState); 31 | setContentView(R.layout.activity_main); 32 | } 33 | 34 | @Override 35 | protected void onPostCreate(@Nullable Bundle savedInstanceState) { 36 | super.onPostCreate(savedInstanceState); 37 | StrictModeCompat.noteSlowCall("Sample"); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /strict-mode-compat/src/main/java/com/kirillr/strictmodehelper/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2021 Kirill Rozov 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.kirillr.strictmodehelper; 18 | 19 | import android.util.Log; 20 | 21 | import androidx.annotation.NonNull; 22 | import androidx.annotation.RestrictTo; 23 | 24 | import com.kirillr.strictmodehelper.StrictModeCompat; 25 | 26 | import java.util.Locale; 27 | 28 | @RestrictTo(RestrictTo.Scope.LIBRARY) 29 | final class Utils { 30 | 31 | private Utils() { 32 | } 33 | 34 | private final static String TAG = "StrictModeCompat"; 35 | private final static String FEATURE_NOT_SUPPORTED_MSG = "%s:%s is not supported"; 36 | 37 | static void logUnsupportedFeature(@NonNull String category, @NonNull String feature) { 38 | Log.d(TAG, String.format(Locale.US, FEATURE_NOT_SUPPORTED_MSG, category, feature)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 21 | 22 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /strict-mode-compat-kotlin/src/main/java/com/kirillr/strictmodehelper/kotlin/dsl/StrictModeConfig.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2021 Kirill Rozov 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.kirillr.strictmodehelper.kotlin.dsl 18 | 19 | @StrictModeDsl 20 | class StrictModeConfig internal constructor(private val enableDefaults: Boolean) { 21 | 22 | internal var threadPolicyConfig: ThreadPolicyConfig? = null 23 | internal var vmPolicyConfig: VmPolicyConfig? = null 24 | 25 | init { 26 | if (enableDefaults) { 27 | threadPolicyConfig = ThreadPolicyConfig(true) 28 | vmPolicyConfig = VmPolicyConfig(true) 29 | } 30 | } 31 | 32 | fun threadPolicy(config: @StrictModeDsl ThreadPolicyConfig.() -> Unit) { 33 | threadPolicyConfig = (threadPolicyConfig ?: ThreadPolicyConfig(enableDefaults)).apply(config) 34 | } 35 | 36 | fun vmPolicy(config: @StrictModeDsl VmPolicyConfig.() -> Unit) { 37 | vmPolicyConfig = (vmPolicyConfig ?: VmPolicyConfig(enableDefaults)).apply(config) 38 | } 39 | } -------------------------------------------------------------------------------- /strict-mode-compat-kotlin/src/main/java/com/kirillr/strictmodehelper/kotlin/StrictModeCompat.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2021 Kirill Rozov 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.kirillr.strictmodehelper.kotlin 18 | 19 | import com.kirillr.strictmodehelper.StrictModeCompat 20 | 21 | /** 22 | * Kotlin extensions for {@link com.kirillr.strictmodehelper.StrictModeCompat} 23 | * 24 | * @author Kirill Rozov 25 | * @date 29/7/17. 26 | */ 27 | @Suppress("unused") 28 | class StrictModeCompat private constructor() { 29 | 30 | companion object { 31 | 32 | /** 33 | * For code to note that it's slow. This is a no-op unless the 34 | * current thread's [android.os.StrictMode.ThreadPolicy] has 35 | * [android.os.StrictMode.ThreadPolicy.Builder.detectCustomSlowCalls] enabled. 36 | * 37 | * @param lazyMessage Short string for the exception stack trace that's built if when this fires. 38 | * 39 | * @see StrictModeCompat.noteSlowCall 40 | */ 41 | @JvmStatic 42 | inline fun noteSlowCall(lazyMessage: () -> String) { 43 | StrictModeCompat.noteSlowCall(lazyMessage()) 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /sample/src/main/kotlin/SampleApplicationKt.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2021 Kirill Rozov 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import android.annotation.SuppressLint 18 | import android.app.Application 19 | import com.kirillr.application.BuildConfig 20 | import com.kirillr.strictmodehelper.kotlin.dsl.initStrictMode 21 | 22 | @SuppressLint("Registered") 23 | class SampleApplicationKt : Application() { 24 | 25 | override fun onCreate() { 26 | super.onCreate() 27 | initStrictMode(enable = BuildConfig.DEVELOPER_MODE, enableDefaults = false) { 28 | threadPolicy { 29 | resourceMismatches = true 30 | customSlowCalls = true 31 | unbufferedIo = true 32 | 33 | penalty { 34 | log = true 35 | threadPolicy { 36 | diskWrites = true 37 | } 38 | } 39 | } 40 | 41 | vmPolicy { 42 | fileUriExposure = true 43 | leakedRegistrationObjects = true 44 | cleartextNetwork = true 45 | untaggedSockets = true 46 | contentUriWithoutPermission = true 47 | 48 | penalty { 49 | log = true 50 | } 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2021 Kirill Rozov 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'com.android.application' 18 | apply plugin: 'kotlin-android' 19 | 20 | android { 21 | compileSdkVersion rootProject.ext.compileSdkVersion 22 | buildToolsVersion rootProject.ext.buildToolsVersion 23 | 24 | defaultConfig { 25 | applicationId "com.kirillr.application" 26 | minSdkVersion rootProject.ext.minSdkVersion 27 | targetSdkVersion rootProject.ext.targetSdkVersion 28 | versionCode getVersionCode(rootProject.ext.versionName) 29 | versionName rootProject.ext.versionName 30 | 31 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 32 | 33 | buildConfigField 'boolean', 'DEVELOPER_MODE', 'false' 34 | } 35 | 36 | buildTypes { 37 | debug { 38 | buildConfigField 'boolean', 'DEVELOPER_MODE', 'true' 39 | } 40 | } 41 | 42 | compileOptions { 43 | sourceCompatibility JavaVersion.VERSION_1_8 44 | targetCompatibility JavaVersion.VERSION_1_8 45 | } 46 | 47 | sourceSets.main.java.srcDirs += 'src/main/kotlin' 48 | 49 | buildFeatures { 50 | buildConfig true 51 | } 52 | } 53 | 54 | dependencies { 55 | implementation "androidx.appcompat:appcompat:$androidXAppCompatVersion" 56 | implementation project(':strict-mode-compat-kotlin') 57 | implementation "org.jetbrains.kotlin:kotlin-stdlib" 58 | } 59 | -------------------------------------------------------------------------------- /sample/src/main/java/com/kirillr/application/SampleApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2021 Kirill Rozov 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.kirillr.application; 18 | 19 | import android.app.Application; 20 | import android.os.StrictMode; 21 | 22 | import com.kirillr.strictmodehelper.StrictModeCompat; 23 | 24 | public class SampleApplication extends Application { 25 | 26 | @Override 27 | public void onCreate() { 28 | super.onCreate(); 29 | if (BuildConfig.DEVELOPER_MODE) { 30 | StrictMode.ThreadPolicy threadPolicy = new StrictModeCompat.ThreadPolicy.Builder() 31 | .detectResourceMismatches() 32 | .detectCustomSlowCalls() 33 | .detectUnbufferedIo() // Available only on Android 8.0+ 34 | .penaltyLog() 35 | .build(); 36 | 37 | StrictMode.VmPolicy vmPolicy = new StrictModeCompat.VmPolicy.Builder() 38 | .detectFileUriExposure() 39 | .detectLeakedRegistrationObjects() 40 | .detectCleartextNetwork() 41 | .detectUntaggedSockets() // Take effect only on Android 8.0+ 42 | .detectContentUriWithoutPermission() // Take effect only on Android 8.0+ 43 | .penaltyLog() 44 | .build(); 45 | 46 | StrictModeCompat.setPolicies(threadPolicy, vmPolicy); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /publishing.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'maven-publish' 2 | apply plugin: 'signing' 3 | 4 | Properties localProps = new Properties() 5 | File localProperties = new File(rootProject.rootDir, "local.properties") 6 | if (localProperties.exists() && localProperties.isFile()) { 7 | localProperties.withInputStream { localProps.load(it) } 8 | } 9 | 10 | project.ext["signing.keyId"] = localProps.getProperty("signing.keyId") 11 | project.ext["signing.secretKeyRingFile"] = localProps.getProperty("signing.secretKeyRingFile") 12 | project.ext["signing.password"] = localProps.getProperty("signing.password") 13 | 14 | java { 15 | withJavadocJar() 16 | withSourcesJar() 17 | } 18 | 19 | afterEvaluate { 20 | publishing { 21 | publications { 22 | releaseJar(MavenPublication) { 23 | from components.java 24 | 25 | groupId = 'com.github.kirich1409' 26 | artifactId = project.ext.artifactId 27 | version = rootProject.ext.versionName 28 | 29 | pom { 30 | name = 'Strict Mode Compat' 31 | description = 'Android Strict Mode Compat' 32 | url = 'https://github.com/kirich1409/StrictModeCompat' 33 | licenses { 34 | license { 35 | name = 'The Apache License, Version 2.0' 36 | url = "http://www.apache.org/licenses/LICENSE-2.0.txt" 37 | } 38 | } 39 | developers { 40 | developer { 41 | id = 'kirich1409' 42 | name = 'Kirill Rozov' 43 | email = 'krl.rozov@gmail.com' 44 | } 45 | } 46 | scm { 47 | url = 'https://github.com/kirich1409/StrictModeCompat.git' 48 | } 49 | } 50 | } 51 | } 52 | 53 | repositories { 54 | maven { 55 | name = "sonatypeStaging" 56 | url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") 57 | credentials { 58 | username = localProps.getProperty("ossrhUsername") 59 | password = localProps.getProperty("ossrhPassword") 60 | } 61 | } 62 | 63 | maven { 64 | name = "sonatypeSnapshots" 65 | url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/") 66 | credentials { 67 | username = localProps.getProperty("ossrhUsername") 68 | password = localProps.getProperty("ossrhPassword") 69 | } 70 | } 71 | } 72 | } 73 | 74 | signing { 75 | sign(publishing.publications) 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /strict-mode-compat-kotlin/src/main/java/com/kirillr/strictmodehelper/kotlin/dsl/StringMode.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2021 Kirill Rozov 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.kirillr.strictmodehelper.kotlin.dsl 18 | 19 | import android.os.StrictMode 20 | import com.kirillr.strictmodehelper.StrictModeCompat 21 | 22 | @Suppress("unused") 23 | fun initStrictMode( 24 | enable: Boolean = true, 25 | enableDefaults: Boolean = true, 26 | config: (StrictModeConfig.() -> Unit) 27 | ) { 28 | if (!enable) return 29 | 30 | with(StrictModeConfig(enableDefaults).apply(config)) { 31 | threadPolicyConfig?.let(::buildThreadPolicy).let(StrictMode::setThreadPolicy) 32 | vmPolicyConfig?.let(::buildVmPolicy).let(StrictMode::setVmPolicy) 33 | } 34 | } 35 | 36 | private fun buildThreadPolicy(config: ThreadPolicyConfig): StrictMode.ThreadPolicy { 37 | return StrictModeCompat.ThreadPolicy.Builder().apply { 38 | with(config) { 39 | if (customSlowCalls) detectCustomSlowCalls() 40 | if (diskReads) detectDiskReads() 41 | if (diskWrites) detectDiskWrites() 42 | if (network) detectNetwork() 43 | if (resourceMismatches) detectResourceMismatches() 44 | if (unbufferedIo) detectUnbufferedIo() 45 | } 46 | 47 | with(config.penaltyConfig) { 48 | if (death) penaltyDeath() 49 | if (deathOnNetwork) penaltyDeathOnNetwork() 50 | if (dialog) penaltyDialog() 51 | if (dropBox) penaltyDropBox() 52 | if (flashScreen) penaltyFlashScreen() 53 | if (log) penaltyLog() 54 | 55 | onViolation?.let { onViolation -> 56 | penaltyListener(checkNotNull(onViolationExecutor), onViolation) 57 | } 58 | } 59 | }.build() 60 | } 61 | 62 | private fun buildVmPolicy(config: VmPolicyConfig): StrictMode.VmPolicy { 63 | return StrictModeCompat.VmPolicy.Builder().apply { 64 | with(config) { 65 | if (activityLeaks) detectActivityLeaks() 66 | if (cleartextNetwork) detectCleartextNetwork() 67 | if (contentUriWithoutPermission) detectContentUriWithoutPermission() 68 | if (fileUriExposure) detectFileUriExposure() 69 | if (leakedClosableObjects) detectLeakedClosableObjects() 70 | if (leakedRegistrationObjects) detectLeakedRegistrationObjects() 71 | if (leakedSqlLiteObjects) detectLeakedSqlLiteObjects() 72 | if (nonSdkApiUsage) detectNonSdkApiUsage() 73 | if (untaggedSockets) detectUntaggedSockets() 74 | if (credentialProtectedWhileLocked) detectCredentialProtectedWhileLocked() 75 | if (implicitDirectBoot) detectImplicitDirectBoot() 76 | 77 | classesInstanceLimit.apply { 78 | if (isNotEmpty()) { 79 | toMap().forEach { (clazz, limit) -> 80 | setClassInstanceLimit(clazz.java, limit) 81 | } 82 | } 83 | } 84 | } 85 | 86 | with(config.penaltyConfig) { 87 | if (death) penaltyDeath() 88 | if (deathOnCleartextNetwork) penaltyDeathOnCleartextNetwork() 89 | if (deathOnFileUriExposure) penaltyDeathOnFileUriExposure() 90 | if (dropBox) penaltyDropBox() 91 | if (log) penaltyLog() 92 | 93 | onViolation?.let { onViolation -> 94 | penaltyListener(checkNotNull(onViolationExecutor), onViolation) 95 | } 96 | } 97 | }.build() 98 | } 99 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Android%20StrictMode%20Compat-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/5655) 2 | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.kirich1409/strict-mode-compat/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.kirich1409/strict-mode-compat) 3 | 4 | Android StrictMode Compat 5 | ========================= 6 | 7 | Wrapper of [StrictMode API](https://developer.android.com/reference/android/os/StrictMode.html) that can be safely called on any version of Android. 8 | You must apply version of library for you project base on compileSdkVersion: 9 | 10 | ```groovy 11 | android { 12 | compileSdkVersion 30 // 30 is required minimum 13 | } 14 | 15 | dependencies { 16 | implementation "com.github.kirich1409:strict-mode-compat:30.2.0" 17 | 18 | // Kotlin Extensions 19 | implementation "com.github.kirich1409:strict-mode-compat-ktx:30.2.0" 20 | } 21 | ``` 22 | 23 | Sample 24 | ------ 25 | 26 | ###### build.gradle ###### 27 | ```groovy 28 | android { 29 | buildTypes { 30 | debug { 31 | buildConfigField 'boolean', 'DEVELOPER_MODE', 'true' 32 | } 33 | 34 | release { 35 | buildConfigField 'boolean', 'DEVELOPER_MODE', 'false' 36 | } 37 | } 38 | } 39 | ``` 40 | 41 | ###### SampleApplication.java ###### 42 | ```java 43 | public class SampleApplication extends Application { 44 | 45 | @Override 46 | public void onCreate() { 47 | super.onCreate(); 48 | if (BuildConfig.DEVELOPER_MODE) { 49 | StrictMode.ThreadPolicy threadPolicy = new StrictModeCompat.ThreadPolicy.Builder() 50 | .detectResourceMismatches() 51 | .detectCustomSlowCalls() 52 | .detectUnbufferedIo() // Available only on Android 8.0+ 53 | .penaltyLog() 54 | .build(); 55 | 56 | StrictMode.VmPolicy vmPolicy = new StrictModeCompat.VmPolicy.Builder() 57 | .detectFileUriExposure() 58 | .detectLeakedRegistrationObjects() 59 | .detectCleartextNetwork() 60 | .detectUntaggedSockets() // Available only on Android 8.0+ 61 | .detectContentUriWithoutPermission() // Available only on Android 8.0+ 62 | .penaltyLog() 63 | .build(); 64 | 65 | StrictModeCompat.setPolicies(threadPolicy, vmPolicy); 66 | } 67 | } 68 | } 69 | ``` 70 | 71 | Or you can use Kotlin extension and configure StrictModeCompat via DSL 72 | ###### SampleApplication.kt ###### 73 | ```kotlin 74 | class SampleApplicationKt : Application() { 75 | 76 | override fun onCreate() { 77 | super.onCreate() 78 | initStrictMode(enable = BuildConfig.DEVELOPER_MODE, enableDefaults = false) { 79 | threadPolicy { 80 | resourceMismatches = true 81 | customSlowCalls = true 82 | unbufferedIo = true 83 | 84 | penalty { 85 | log = true 86 | } 87 | } 88 | 89 | vmPolicy { 90 | fileUriExposure = true 91 | leakedRegistrationObjects = true 92 | cleartextNetwork = true 93 | cleartextNetwork = true 94 | untaggedSockets = true 95 | contentUriWithoutPermission = true 96 | 97 | penalty { 98 | log = true 99 | } 100 | } 101 | } 102 | } 103 | } 104 | ``` 105 | 106 | License 107 | ------- 108 | 109 | Copyright 2017-2021 Kirill Rozov 110 | 111 | Licensed under the Apache License, Version 2.0 (the "License"); 112 | you may not use this file except in compliance with the License. 113 | You may obtain a copy of the License at 114 | 115 | http://www.apache.org/licenses/LICENSE-2.0 116 | 117 | Unless required by applicable law or agreed to in writing, software 118 | distributed under the License is distributed on an "AS IS" BASIS, 119 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 120 | See the License for the specific language governing permissions and 121 | limitations under the License. 122 | -------------------------------------------------------------------------------- /strict-mode-compat-kotlin/src/main/java/com/kirillr/strictmodehelper/kotlin/dsl/VmPolicyConfig.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("unused") 2 | 3 | package com.kirillr.strictmodehelper.kotlin.dsl 4 | 5 | import android.os.Build 6 | import android.os.StrictMode 7 | import android.os.strictmode.Violation 8 | import java.util.concurrent.Executor 9 | import kotlin.reflect.KClass 10 | 11 | @VmPolicyDsl 12 | class VmPolicyConfig private constructor( 13 | var activityLeaks: Boolean, 14 | var cleartextNetwork: Boolean, 15 | var contentUriWithoutPermission: Boolean, 16 | var fileUriExposure: Boolean, 17 | var leakedClosableObjects: Boolean, 18 | var leakedRegistrationObjects: Boolean, 19 | var leakedSqlLiteObjects: Boolean, 20 | var nonSdkApiUsage: Boolean, 21 | var untaggedSockets: Boolean, 22 | var implicitDirectBoot: Boolean, 23 | var credentialProtectedWhileLocked: Boolean, 24 | internal val penaltyConfig: PenaltyConfig 25 | ) { 26 | 27 | var classesInstanceLimit = mapOf, Int>() 28 | 29 | fun penalty(config: (@VmPolicyDsl PenaltyConfig.() -> Unit)) { 30 | this.penaltyConfig.apply(config) 31 | } 32 | 33 | internal companion object { 34 | 35 | internal operator fun invoke(enableDefaults: Boolean): VmPolicyConfig { 36 | return if (enableDefaults) default() else disableAll() 37 | } 38 | 39 | private fun disableAll(): VmPolicyConfig { 40 | return VmPolicyConfig( 41 | activityLeaks = false, 42 | cleartextNetwork = false, 43 | contentUriWithoutPermission = false, 44 | fileUriExposure = false, 45 | leakedClosableObjects = false, 46 | leakedSqlLiteObjects = false, 47 | leakedRegistrationObjects = false, 48 | nonSdkApiUsage = false, 49 | untaggedSockets = false, 50 | implicitDirectBoot = false, 51 | credentialProtectedWhileLocked = false, 52 | penaltyConfig = PenaltyConfig(false) 53 | ) 54 | } 55 | 56 | private fun default(): VmPolicyConfig { 57 | return VmPolicyConfig( 58 | activityLeaks = DEFAULT_ACTIVITY_LEAKS, 59 | cleartextNetwork = DEFAULT_CLEARTEXT_NETWORK, 60 | contentUriWithoutPermission = DEFAULT_CONTENT_URI_WITHOUT_PERMISSION, 61 | fileUriExposure = DEFAULT_FILE_URI_EXPOSURE, 62 | leakedClosableObjects = DEFAULT_LEAKED_CLOSABLE_OBJECTS, 63 | leakedSqlLiteObjects = DEFAULT_LEAKED_SQL_LITE_OBJECTS, 64 | leakedRegistrationObjects = DEFAULT_LEAKED_REGISTRATION_OBJECTS, 65 | nonSdkApiUsage = DEFAULT_NON_SDK_API_USAGE, 66 | untaggedSockets = DEFAULT_UNTAGGED_SOCKETS, 67 | implicitDirectBoot = DEFAULT_IMPLICIT_DIRECT_BOOT, 68 | credentialProtectedWhileLocked = DEFAULT_CREDENTIAL_PROTECTED_WHILE_LOCKED, 69 | penaltyConfig = PenaltyConfig(true) 70 | ) 71 | } 72 | 73 | private const val DEFAULT_ACTIVITY_LEAKS = true 74 | private const val DEFAULT_CLEARTEXT_NETWORK = true 75 | private const val DEFAULT_CONTENT_URI_WITHOUT_PERMISSION = true 76 | private const val DEFAULT_FILE_URI_EXPOSURE = true 77 | private const val DEFAULT_LEAKED_CLOSABLE_OBJECTS = true 78 | private const val DEFAULT_LEAKED_REGISTRATION_OBJECTS = true 79 | private const val DEFAULT_LEAKED_SQL_LITE_OBJECTS = true 80 | private const val DEFAULT_NON_SDK_API_USAGE = true 81 | private const val DEFAULT_UNTAGGED_SOCKETS = true 82 | private const val DEFAULT_IMPLICIT_DIRECT_BOOT = true 83 | private const val DEFAULT_CREDENTIAL_PROTECTED_WHILE_LOCKED = true 84 | } 85 | 86 | class PenaltyConfig private constructor( 87 | var death: Boolean, 88 | var deathOnCleartextNetwork: Boolean, 89 | var deathOnFileUriExposure: Boolean, 90 | var dropBox: Boolean, 91 | var log: Boolean 92 | ) { 93 | 94 | internal var onViolation: ((violation: Violation) -> Unit)? = null 95 | internal var onViolationExecutor: Executor? = null 96 | 97 | /** 98 | * Call [StrictMode.OnThreadViolationListener.onThreadViolation] on specified [executor] every violation. 99 | * 100 | * Work on [Build.VERSION_CODES.P] and newer. 101 | */ 102 | fun onViolation(executor: Executor, body: (violation: Violation) -> Unit) { 103 | onViolationExecutor = executor 104 | this.onViolation = body 105 | } 106 | 107 | internal companion object { 108 | 109 | internal operator fun invoke(enableDefaults: Boolean): PenaltyConfig { 110 | return if (enableDefaults) default() else disableAll() 111 | } 112 | 113 | private fun disableAll(): PenaltyConfig { 114 | return PenaltyConfig( 115 | death = false, 116 | deathOnCleartextNetwork = false, 117 | deathOnFileUriExposure = false, 118 | dropBox = false, 119 | log = false 120 | ) 121 | } 122 | 123 | private fun default(): PenaltyConfig { 124 | return PenaltyConfig( 125 | death = DEFAULT_DEATH, 126 | deathOnCleartextNetwork = DEFAULT_DEATH_ON_CLEARTEXT_NETWORK, 127 | deathOnFileUriExposure = DEFAULT_DEATH_ON_FILE_URI_EXPOSURE, 128 | dropBox = DEFAULT_DROPBOX, 129 | log = DEFAULT_LOG 130 | ) 131 | } 132 | 133 | private const val DEFAULT_DEATH = false 134 | private const val DEFAULT_DEATH_ON_CLEARTEXT_NETWORK = false 135 | private const val DEFAULT_DEATH_ON_FILE_URI_EXPOSURE = false 136 | private const val DEFAULT_DROPBOX = false 137 | private const val DEFAULT_LOG = true 138 | } 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /strict-mode-compat-kotlin/src/main/java/com/kirillr/strictmodehelper/kotlin/dsl/ThreadPolicyConfig.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2021 Kirill Rozov 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:Suppress("unused") 18 | 19 | package com.kirillr.strictmodehelper.kotlin.dsl 20 | 21 | import android.os.strictmode.Violation 22 | import java.util.concurrent.Executor 23 | import android.os.DropBoxManager 24 | import android.os.StrictMode 25 | import android.os.Build 26 | 27 | @ThreadPolicyDsl 28 | class ThreadPolicyConfig private constructor( 29 | /** 30 | * Enable detection of slow calls. 31 | */ 32 | var customSlowCalls: Boolean, 33 | 34 | /** 35 | * Enable detection of disk reads. 36 | */ 37 | var diskReads: Boolean, 38 | 39 | /** 40 | * Enable detection of disk writes. 41 | */ 42 | var diskWrites: Boolean, 43 | 44 | /** 45 | * Enable detection of network operations. 46 | */ 47 | var network: Boolean, 48 | 49 | /** 50 | * Enables detection of mismatches between defined resource types and getter calls. 51 | */ 52 | var resourceMismatches: Boolean, 53 | 54 | /** 55 | * Detect unbuffered input/output operations. 56 | */ 57 | var unbufferedIo: Boolean, 58 | 59 | internal val penaltyConfig: PenaltyConfig 60 | ) { 61 | 62 | fun penalty(config: @ThreadPolicyDsl PenaltyConfig.() -> Unit) { 63 | this.penaltyConfig.apply(config) 64 | } 65 | 66 | internal companion object { 67 | 68 | internal operator fun invoke(enableDefaults: Boolean): ThreadPolicyConfig { 69 | return if (enableDefaults) default() else disableAll() 70 | } 71 | 72 | private fun disableAll(): ThreadPolicyConfig { 73 | return ThreadPolicyConfig( 74 | customSlowCalls = false, 75 | diskReads = false, 76 | diskWrites = false, 77 | network = false, 78 | resourceMismatches = false, 79 | unbufferedIo = false, 80 | penaltyConfig = PenaltyConfig(false) 81 | ) 82 | } 83 | 84 | private fun default(): ThreadPolicyConfig { 85 | return ThreadPolicyConfig( 86 | customSlowCalls = DEFAULT_CUSTOM_SLOW_CALLS, 87 | diskReads = DEFAULT_DISK_READS, 88 | diskWrites = DEFAULT_DISK_WRITES, 89 | network = DEFAULT_NETWORK, 90 | resourceMismatches = DEFAULT_RESOURCE_MISMATCHES, 91 | unbufferedIo = DEFAULT_UNBUFFERED_IO, 92 | penaltyConfig = PenaltyConfig(true) 93 | ) 94 | } 95 | 96 | private const val DEFAULT_CUSTOM_SLOW_CALLS = true 97 | private const val DEFAULT_DISK_READS = true 98 | private const val DEFAULT_DISK_WRITES = true 99 | private const val DEFAULT_NETWORK = true 100 | private const val DEFAULT_RESOURCE_MISMATCHES = true 101 | private const val DEFAULT_UNBUFFERED_IO = true 102 | } 103 | 104 | class PenaltyConfig private constructor( 105 | /** 106 | * Crash the whole process on violation. This penalty runs at the end of all enabled penalties so you'll 107 | * still get see logging or other violations before the process dies. 108 | * 109 | * Unlike [deathOnNetwork], this applies to disk reads, disk writes, and network usage if their 110 | * corresponding detect flags are set. 111 | */ 112 | var death: Boolean, 113 | 114 | /** 115 | * Crash the whole process on any network usage. Unlike [death], this penalty runs 116 | * *before* anything else. You must still have enable [network]. 117 | */ 118 | var deathOnNetwork: Boolean, 119 | 120 | /** 121 | * Show an annoying dialog to the developer on detected violations, rate-limited to be only a little annoying. 122 | */ 123 | var dialog: Boolean, 124 | 125 | /** 126 | * Enable detected violations log a stacktrace and timing data to the [DropBox][DropBoxManager] 127 | * on policy violation. Intended mostly for platform integrators doing beta user field data collection. 128 | */ 129 | var dropBox: Boolean, 130 | 131 | /** 132 | * Flash the screen during a violation. 133 | */ 134 | var flashScreen: Boolean, 135 | 136 | /** 137 | * Log detected violations to the system log. 138 | */ 139 | var log: Boolean 140 | ) { 141 | 142 | internal var onViolation: ((violation: Violation) -> Unit)? = null 143 | internal var onViolationExecutor: Executor? = null 144 | 145 | /** 146 | * Call [StrictMode.OnThreadViolationListener.onThreadViolation] on specified [executor] every violation. 147 | * 148 | * Work on [Build.VERSION_CODES.P] and newer. 149 | */ 150 | fun onViolation(executor: Executor, body: (violation: Violation) -> Unit) { 151 | onViolationExecutor = executor 152 | this.onViolation = body 153 | } 154 | 155 | internal companion object { 156 | 157 | internal operator fun invoke(enableDefaults: Boolean): PenaltyConfig { 158 | return if (enableDefaults) default() else disableAll() 159 | } 160 | 161 | private fun disableAll(): PenaltyConfig { 162 | return PenaltyConfig( 163 | death = false, 164 | deathOnNetwork = false, 165 | dialog = false, 166 | dropBox = false, 167 | flashScreen = false, 168 | log = false 169 | ) 170 | } 171 | 172 | private fun default(): PenaltyConfig { 173 | return PenaltyConfig( 174 | death = DEFAULT_DEATH, 175 | deathOnNetwork = DEFAULT_DEATH_ON_NETWORK, 176 | dialog = DEFAULT_DIALOG, 177 | dropBox = DEFAULT_DROPBOX, 178 | flashScreen = DEFAULT_FLASH_SCREEN, 179 | log = DEFAULT_LOG 180 | ) 181 | } 182 | 183 | private const val DEFAULT_DEATH = false 184 | private const val DEFAULT_DEATH_ON_NETWORK = false 185 | private const val DEFAULT_DIALOG = false 186 | private const val DEFAULT_DROPBOX = false 187 | private const val DEFAULT_FLASH_SCREEN = false 188 | private const val DEFAULT_LOG = true 189 | } 190 | } 191 | } 192 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2020 Kirill Rozov 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /strict-mode-compat/src/main/java/com/kirillr/strictmodehelper/StrictModeCompat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2021 Kirill Rozov 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.kirillr.strictmodehelper; 18 | 19 | import android.annotation.TargetApi; 20 | import android.app.Activity; 21 | import android.content.BroadcastReceiver; 22 | import android.content.Context; 23 | import android.content.Intent; 24 | import android.content.ServiceConnection; 25 | import android.content.res.TypedArray; 26 | import android.database.sqlite.SQLiteCursor; 27 | import android.net.Uri; 28 | import android.os.Build; 29 | import android.os.DropBoxManager; 30 | import android.os.StrictMode; 31 | import android.os.strictmode.Violation; 32 | 33 | import java.io.Closeable; 34 | import java.util.Locale; 35 | import java.util.concurrent.Executor; 36 | 37 | import androidx.annotation.IntRange; 38 | import androidx.annotation.NonNull; 39 | import androidx.annotation.Nullable; 40 | 41 | @SuppressWarnings("ALL") 42 | public final class StrictModeCompat { 43 | 44 | private StrictModeCompat() { 45 | } 46 | 47 | /** 48 | * A convenience wrapper that takes the current 49 | * {@link ThreadPolicy} from {@link #getThreadPolicy}, modifies it 50 | * to permit disk reads, and sets the new policy 51 | * with {@link #setThreadPolicy}, returning the old policy so you 52 | * can restore it at the end of a block. 53 | * 54 | * @return the old policy, to be passed to setThreadPolicy to restore the policy. 55 | */ 56 | @NonNull 57 | public static StrictMode.ThreadPolicy allowThreadDiskReads() { 58 | return StrictMode.allowThreadDiskReads(); 59 | } 60 | 61 | /** 62 | * A convenience wrapper that takes the current 63 | * {@link ThreadPolicy} from {@link #getThreadPolicy}, modifies it 64 | * to permit both disk reads & writes, and sets the new policy 65 | * with {@link #setThreadPolicy}, returning the old policy so you 66 | * can restore it at the end of a block. 67 | * 68 | * @return the old policy, to be passed to {@link #setThreadPolicy} to 69 | * restore the policy at the end of a block 70 | */ 71 | @NonNull 72 | public static StrictMode.ThreadPolicy allowThreadDiskWrites() { 73 | return StrictMode.allowThreadDiskWrites(); 74 | } 75 | 76 | /** 77 | * Enable the recommended StrictMode defaults, with violations just being logged. 78 | *

79 | *

This catches disk and network access on the main thread, as 80 | * well as leaked SQLite cursors and unclosed resources. This is 81 | * simply a wrapper around {@link #setVmPolicy} and {@link 82 | * #setThreadPolicy}. 83 | */ 84 | public static void enableDefaults() { 85 | StrictMode.enableDefaults(); 86 | } 87 | 88 | /** 89 | * Returns the current thread's policy. 90 | * 91 | * @see StrictMode#getThreadPolicy() 92 | */ 93 | @NonNull 94 | public static StrictMode.ThreadPolicy getThreadPolicy() { 95 | return StrictMode.getThreadPolicy(); 96 | } 97 | 98 | /** 99 | * Gets the current VM policy. 100 | */ 101 | @NonNull 102 | public static StrictMode.VmPolicy getVmPolicy() { 103 | return StrictMode.getVmPolicy(); 104 | } 105 | 106 | /** 107 | * For code to note that it's slow. This is a no-op unless the 108 | * current thread's {@link android.os.StrictMode.ThreadPolicy} has 109 | * {@link android.os.StrictMode.ThreadPolicy.Builder#detectCustomSlowCalls} 110 | * enabled. 111 | * 112 | * @param name Short string for the exception stack trace that's 113 | * built if when this fires. 114 | * @see StrictModeCompat#noteSlowCall(String, Object...) 115 | * @see StrictModeCompat#noteSlowCall(Locale, String, Object...) 116 | */ 117 | public static void noteSlowCall(@NonNull String name) { 118 | StrictMode.noteSlowCall(name); 119 | } 120 | 121 | /** 122 | * For code to note that it's slow. This is a no-op unless the 123 | * current thread's {@link android.os.StrictMode.ThreadPolicy} has 124 | * {@link android.os.StrictMode.ThreadPolicy.Builder#detectCustomSlowCalls} 125 | * enabled. 126 | * 127 | * @param message Short formatting string for the exception stack trace that's 128 | * built if when this fires. 129 | * @param args Arguments referenced by the format specifiers in the format string 130 | * @see StrictModeCompat#noteSlowCall(String) 131 | * @see StrictModeCompat#noteSlowCall(Locale, String, Object...) 132 | */ 133 | public static void noteSlowCall(@NonNull String message, @NonNull Object... args) { 134 | StrictMode.noteSlowCall(String.format(message, args)); 135 | } 136 | 137 | /** 138 | * For code to note that it's slow. This is a no-op unless the 139 | * current thread's {@link android.os.StrictMode.ThreadPolicy} has 140 | * {@link android.os.StrictMode.ThreadPolicy.Builder#detectCustomSlowCalls} 141 | * enabled. 142 | * 143 | * @param locale The locale to apply during formatting 144 | * @param message Short formatting string for the exception stack trace that's 145 | * built if when this fires. 146 | * @param args Arguments referenced by the format specifiers in the format string 147 | * @see StrictModeCompat#noteSlowCall(String) 148 | * @see StrictModeCompat#noteSlowCall(String, Object...) 149 | */ 150 | public static void noteSlowCall(@Nullable Locale locale, @NonNull String message, @NonNull Object... args) { 151 | if (locale == null) { 152 | StrictMode.noteSlowCall(String.format(message, args)); 153 | } else { 154 | StrictMode.noteSlowCall(String.format(locale, message, args)); 155 | } 156 | } 157 | 158 | /** 159 | * Sets the policy for what actions on the current thread should 160 | * be detected, as well as the penalty if such actions occur. 161 | *

162 | *

Internally this sets a thread-local variable which is 163 | * propagated across cross-process IPC calls, meaning you can 164 | * catch violations when a system service or another process 165 | * accesses the disk or network on your behalf. 166 | * 167 | * @param policy the policy to put into place 168 | */ 169 | public static void setThreadPolicy(@NonNull StrictMode.ThreadPolicy policy) { 170 | StrictMode.setThreadPolicy(policy); 171 | } 172 | 173 | /** 174 | * Sets the policy for what actions in the VM process (on any 175 | * thread) should be detected, as well as the penalty if such 176 | * actions occur. 177 | * 178 | * @param policy the policy to put into place 179 | */ 180 | public static void setVmPolicy(@NonNull StrictMode.VmPolicy policy) { 181 | StrictMode.setVmPolicy(policy); 182 | } 183 | 184 | /** 185 | * Set Thread and VM policies in one method. 186 | * 187 | * @param threadPolicy the thread policy to put into place 188 | * @param vmPolicy the vm policy to put into place 189 | */ 190 | public static void setPolicies( 191 | @NonNull StrictMode.ThreadPolicy threadPolicy, 192 | @NonNull StrictMode.VmPolicy vmPolicy 193 | ) { 194 | setThreadPolicy(threadPolicy); 195 | setVmPolicy(vmPolicy); 196 | } 197 | 198 | /** 199 | * When {@link StrictMode.VmPolicy.Builder#penaltyListener(Executor, StrictMode.OnVmViolationListener)} is enabled, 200 | * the listener is called on the provided executor when a VM violation occurs. 201 | */ 202 | public interface OnVmViolationListener { 203 | 204 | /** 205 | * Called on a VM policy violation. 206 | */ 207 | @TargetApi(Build.VERSION_CODES.O) 208 | void onVmViolation(@NonNull Violation violation); 209 | } 210 | 211 | /** 212 | * When {@link StrictMode.ThreadPolicy.Builder#penaltyListener(Executor, StrictMode.OnThreadViolationListener)} is enabled, 213 | * the listener is called on the provided executor when a Thread violation occurs. 214 | */ 215 | public interface OnThreadViolationListener { 216 | 217 | /** 218 | * Called on a thread policy violation. 219 | */ 220 | @TargetApi(Build.VERSION_CODES.O) 221 | void onThreadViolation(@NonNull Violation violation); 222 | } 223 | 224 | public static final class ThreadPolicy { 225 | 226 | private ThreadPolicy() { 227 | } 228 | 229 | public static final class Builder { 230 | 231 | @NonNull 232 | private final BuilderImpl mBuilder; 233 | 234 | public Builder() { 235 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { 236 | mBuilder = new V28BuilderImpl(); 237 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 238 | mBuilder = new V26BuilderImpl(); 239 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 240 | mBuilder = new V23BuilderImpl(); 241 | } else { 242 | mBuilder = new V14BuilderImpl(); 243 | } 244 | } 245 | 246 | public Builder(@NonNull StrictMode.ThreadPolicy policy) { 247 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { 248 | mBuilder = new V28BuilderImpl(policy); 249 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 250 | mBuilder = new V26BuilderImpl(policy); 251 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 252 | mBuilder = new V23BuilderImpl(policy); 253 | } else { 254 | mBuilder = new V14BuilderImpl(policy); 255 | } 256 | } 257 | 258 | /** 259 | * Construct the ThreadPolicy instance. 260 | *

261 | *

Note: if no penalties are enabled before calling 262 | * build, {@link #penaltyLog} is implicitly 263 | * set. 264 | */ 265 | public StrictMode.ThreadPolicy build() { 266 | return mBuilder.build(); 267 | } 268 | 269 | /** 270 | * Detect everything that's potentially suspect. 271 | */ 272 | public Builder detectAll() { 273 | mBuilder.detectAll(); 274 | return this; 275 | } 276 | 277 | /** 278 | * Enable detection of slow calls. 279 | */ 280 | public Builder detectCustomSlowCalls() { 281 | mBuilder.detectCustomSlowCalls(); 282 | return this; 283 | } 284 | 285 | /** 286 | * Enable detection of disk reads. 287 | */ 288 | public Builder detectDiskReads() { 289 | mBuilder.detectDiskReads(); 290 | return this; 291 | } 292 | 293 | /** 294 | * Enable detection of disk writes. 295 | */ 296 | public Builder detectDiskWrites() { 297 | mBuilder.detectDiskWrites(); 298 | return this; 299 | } 300 | 301 | /** 302 | * Enable detection of network operations. 303 | */ 304 | public Builder detectNetwork() { 305 | mBuilder.detectNetwork(); 306 | return this; 307 | } 308 | 309 | /** 310 | * Enables detection of mismatches between defined resource types 311 | * and getter calls. 312 | *

313 | * This helps detect accidental type mismatches and potentially 314 | * expensive type conversions when obtaining typed resources. 315 | *

316 | * For example, a strict mode violation would be thrown when 317 | * calling {@link TypedArray#getInt(int, int)} 318 | * on an index that contains a String-type resource. If the string 319 | * value can be parsed as an integer, this method call will return 320 | * a value without crashing; however, the developer should format 321 | * the resource as an integer to avoid unnecessary type conversion. 322 | */ 323 | public Builder detectResourceMismatches() { 324 | mBuilder.detectResourceMismatches(); 325 | return this; 326 | } 327 | 328 | /** 329 | * Crash the whole process on violation. This penalty runs at 330 | * the end of all enabled penalties so you'll still get 331 | * see logging or other violations before the process dies. 332 | *

333 | *

Unlike {@link #penaltyDeathOnNetwork}, this applies 334 | * to disk reads, disk writes, and network usage if their 335 | * corresponding detect flags are set. 336 | */ 337 | public Builder penaltyDeath() { 338 | mBuilder.penaltyDeath(); 339 | return this; 340 | } 341 | 342 | /** 343 | * Crash the whole process on any network usage. Unlike 344 | * {@link #penaltyDeath}, this penalty runs 345 | * before anything else. You must still have 346 | * called {@link #detectNetwork} to enable this. 347 | *

348 | *

In the Honeycomb or later SDKs, this is on by default. 349 | */ 350 | public Builder penaltyDeathOnNetwork() { 351 | mBuilder.penaltyDeathOnNetwork(); 352 | return this; 353 | } 354 | 355 | /** 356 | * Show an annoying dialog to the developer on detected 357 | * violations, rate-limited to be only a little annoying. 358 | */ 359 | public Builder penaltyDialog() { 360 | mBuilder.penaltyDialog(); 361 | return this; 362 | } 363 | 364 | /** 365 | * Enable detected violations log a stacktrace and timing data 366 | * to the {@link DropBoxManager DropBox} on policy 367 | * violation. Intended mostly for platform integrators doing 368 | * beta user field data collection. 369 | */ 370 | public Builder penaltyDropBox() { 371 | mBuilder.penaltyDropBox(); 372 | return this; 373 | } 374 | 375 | /** 376 | * Flash the screen during a violation. 377 | */ 378 | public Builder penaltyFlashScreen() { 379 | mBuilder.penaltyFlashScreen(); 380 | return this; 381 | } 382 | 383 | /** 384 | * Log detected violations to the system log. 385 | */ 386 | public Builder penaltyLog() { 387 | mBuilder.penaltyLog(); 388 | return this; 389 | } 390 | 391 | /** 392 | * Disable the detection of everything. 393 | */ 394 | public Builder permitAll() { 395 | mBuilder.permitAll(); 396 | return this; 397 | } 398 | 399 | /** 400 | * Disable detection of slow calls. 401 | */ 402 | public Builder permitCustomSlowCalls() { 403 | mBuilder.permitCustomSlowCalls(); 404 | return this; 405 | } 406 | 407 | /** 408 | * Disable detection of disk reads. 409 | */ 410 | public Builder permitDiskReads() { 411 | mBuilder.permitDiskReads(); 412 | return this; 413 | } 414 | 415 | /** 416 | * Disable detection of disk writes. 417 | */ 418 | public Builder permitDiskWrites() { 419 | mBuilder.permitDiskWrites(); 420 | return this; 421 | } 422 | 423 | /** 424 | * Disable detection of network operations. 425 | */ 426 | public Builder permitNetwork() { 427 | mBuilder.permitNetwork(); 428 | return this; 429 | } 430 | 431 | /** 432 | * Disable detection of mismatches between defined resource types 433 | * and getter calls. 434 | */ 435 | public Builder permitResourceMismatches() { 436 | mBuilder.permitResourceMismatches(); 437 | return this; 438 | } 439 | 440 | /** 441 | * Detect unbuffered input/output operations. 442 | *

443 | * Work on {@link Build.VERSION_CODES#O} and newer. 444 | */ 445 | public Builder detectUnbufferedIo() { 446 | mBuilder.detectUnbufferedIo(); 447 | return this; 448 | } 449 | 450 | /** 451 | * Disable detection of unbuffered input/output operations. 452 | *

453 | * Work on {@link Build.VERSION_CODES#O} and newer. 454 | */ 455 | public Builder permitUnbufferedIo() { 456 | mBuilder.permitUnbufferedIo(); 457 | return this; 458 | } 459 | 460 | /** 461 | * Call {@link StrictMode.OnThreadViolationListener#onThreadViolation(Violation)} 462 | * on specified executor every violation. 463 | *

464 | * Work on {@link Build.VERSION_CODES#P} and newer. 465 | * 466 | * @param executor This value must never be null. 467 | * @param listener This value must never be null. 468 | */ 469 | public Builder penaltyListener( 470 | @NonNull Executor executor, 471 | @NonNull OnThreadViolationListener listener 472 | ) { 473 | mBuilder.penaltyListener(executor, listener); 474 | return this; 475 | } 476 | } 477 | 478 | private interface BuilderImpl { 479 | 480 | String CATEGORY = "ThreadPolicy"; 481 | 482 | StrictMode.ThreadPolicy build(); 483 | 484 | void detectAll(); 485 | 486 | void detectCustomSlowCalls(); 487 | 488 | void detectDiskReads(); 489 | 490 | void detectDiskWrites(); 491 | 492 | void detectNetwork(); 493 | 494 | void penaltyDeath(); 495 | 496 | void penaltyDeathOnNetwork(); 497 | 498 | void penaltyDialog(); 499 | 500 | void penaltyDropBox(); 501 | 502 | void penaltyFlashScreen(); 503 | 504 | void penaltyLog(); 505 | 506 | void permitAll(); 507 | 508 | void permitCustomSlowCalls(); 509 | 510 | void permitDiskReads(); 511 | 512 | void permitDiskWrites(); 513 | 514 | void permitNetwork(); 515 | 516 | // Min sdk 23 517 | void detectResourceMismatches(); 518 | 519 | // Min sdk 23 520 | void permitResourceMismatches(); 521 | 522 | // Min sdk 26 523 | void detectUnbufferedIo(); 524 | 525 | // Min sdk 26 526 | void permitUnbufferedIo(); 527 | 528 | // Min sdk 28 529 | void penaltyListener(@NonNull Executor executor, @NonNull OnThreadViolationListener listener); 530 | } 531 | 532 | private static class V14BuilderImpl implements BuilderImpl { 533 | 534 | @NonNull 535 | final StrictMode.ThreadPolicy.Builder builder; 536 | 537 | V14BuilderImpl() { 538 | this.builder = new StrictMode.ThreadPolicy.Builder(); 539 | } 540 | 541 | V14BuilderImpl(@NonNull StrictMode.ThreadPolicy policy) { 542 | this.builder = new StrictMode.ThreadPolicy.Builder(policy); 543 | } 544 | 545 | @Override 546 | public void detectCustomSlowCalls() { 547 | builder.detectCustomSlowCalls(); 548 | } 549 | 550 | @Override 551 | public void penaltyDeathOnNetwork() { 552 | builder.penaltyDeathOnNetwork(); 553 | } 554 | 555 | @Override 556 | public void penaltyFlashScreen() { 557 | builder.penaltyFlashScreen(); 558 | } 559 | 560 | @Override 561 | public void permitCustomSlowCalls() { 562 | builder.permitCustomSlowCalls(); 563 | } 564 | 565 | @Override 566 | public StrictMode.ThreadPolicy build() { 567 | return builder.build(); 568 | } 569 | 570 | @Override 571 | public void detectAll() { 572 | builder.detectAll(); 573 | } 574 | 575 | @Override 576 | public void detectDiskReads() { 577 | builder.detectDiskReads(); 578 | } 579 | 580 | @Override 581 | public void detectDiskWrites() { 582 | builder.detectDiskWrites(); 583 | } 584 | 585 | @Override 586 | public void detectNetwork() { 587 | builder.detectNetwork(); 588 | } 589 | 590 | @Override 591 | public void penaltyDeath() { 592 | builder.penaltyDeath(); 593 | } 594 | 595 | @Override 596 | public void penaltyDialog() { 597 | builder.penaltyDialog(); 598 | } 599 | 600 | @Override 601 | public void penaltyDropBox() { 602 | builder.penaltyDropBox(); 603 | } 604 | 605 | @Override 606 | public void penaltyLog() { 607 | builder.penaltyLog(); 608 | } 609 | 610 | @Override 611 | public void permitAll() { 612 | builder.permitAll(); 613 | } 614 | 615 | @Override 616 | public void permitDiskReads() { 617 | builder.permitDiskReads(); 618 | } 619 | 620 | @Override 621 | public void permitDiskWrites() { 622 | builder.permitDiskWrites(); 623 | } 624 | 625 | @Override 626 | public void permitNetwork() { 627 | builder.permitNetwork(); 628 | } 629 | 630 | // Min sdk 23 631 | @Override 632 | public void detectResourceMismatches() { 633 | Utils.logUnsupportedFeature(CATEGORY, "Resource mismatches"); 634 | } 635 | 636 | // Min sdk 23 637 | @Override 638 | public void permitResourceMismatches() { 639 | Utils.logUnsupportedFeature(CATEGORY, "Resource mismatches"); 640 | } 641 | 642 | // Min sdk 26 643 | @Override 644 | public void detectUnbufferedIo() { 645 | Utils.logUnsupportedFeature(CATEGORY, "Unbuffered IO"); 646 | } 647 | 648 | // Min sdk 26 649 | @Override 650 | public void permitUnbufferedIo() { 651 | Utils.logUnsupportedFeature(CATEGORY, "Unbuffered IO"); 652 | } 653 | 654 | // Min sdk 28 655 | @Override 656 | public void penaltyListener(@NonNull Executor executor, @NonNull OnThreadViolationListener listener) { 657 | Utils.logUnsupportedFeature(CATEGORY, "Penalty listener"); 658 | } 659 | } 660 | 661 | @TargetApi(Build.VERSION_CODES.M) 662 | private static class V23BuilderImpl extends V14BuilderImpl { 663 | 664 | V23BuilderImpl() { 665 | } 666 | 667 | V23BuilderImpl(@NonNull StrictMode.ThreadPolicy policy) { 668 | super(policy); 669 | } 670 | 671 | @Override 672 | public void detectResourceMismatches() { 673 | builder.detectResourceMismatches(); 674 | } 675 | 676 | @Override 677 | public void permitResourceMismatches() { 678 | builder.permitResourceMismatches(); 679 | } 680 | } 681 | 682 | @TargetApi(Build.VERSION_CODES.O) 683 | private static class V26BuilderImpl extends V23BuilderImpl { 684 | 685 | V26BuilderImpl() { 686 | } 687 | 688 | V26BuilderImpl(@NonNull StrictMode.ThreadPolicy policy) { 689 | super(policy); 690 | } 691 | 692 | @Override 693 | public void detectUnbufferedIo() { 694 | builder.detectUnbufferedIo(); 695 | } 696 | 697 | @Override 698 | public void permitUnbufferedIo() { 699 | builder.permitUnbufferedIo(); 700 | } 701 | } 702 | 703 | @TargetApi(Build.VERSION_CODES.P) 704 | private static class V28BuilderImpl extends V26BuilderImpl { 705 | 706 | V28BuilderImpl() { 707 | } 708 | 709 | V28BuilderImpl(@NonNull StrictMode.ThreadPolicy policy) { 710 | super(policy); 711 | } 712 | 713 | @Override 714 | public void penaltyListener( 715 | @NonNull Executor executor, 716 | @NonNull final OnThreadViolationListener listener 717 | ) { 718 | builder.penaltyListener( 719 | executor, 720 | new StrictMode.OnThreadViolationListener() { 721 | 722 | @Override 723 | public void onThreadViolation(Violation violation) { 724 | listener.onThreadViolation(violation); 725 | } 726 | } 727 | ); 728 | } 729 | } 730 | } 731 | 732 | public static final class VmPolicy { 733 | 734 | private VmPolicy() { 735 | } 736 | 737 | public static final class Builder { 738 | 739 | @NonNull 740 | private final BuilderImpl mBuilder; 741 | 742 | public Builder() { 743 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { 744 | mBuilder = new V29BuilderImpl(); 745 | 746 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { 747 | mBuilder = new V28BuilderImpl(); 748 | 749 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 750 | mBuilder = new V26BuilderImpl(); 751 | 752 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { 753 | mBuilder = new V24BuilderImpl(); 754 | 755 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 756 | mBuilder = new V23BuilderImpl(); 757 | 758 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { 759 | mBuilder = new V18BuilderImpl(); 760 | 761 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { 762 | mBuilder = new V16BuilderImpl(); 763 | 764 | } else { 765 | mBuilder = new V14BuilderImpl(); 766 | } 767 | } 768 | 769 | public Builder(@NonNull StrictMode.VmPolicy policy) { 770 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { 771 | mBuilder = new V29BuilderImpl(policy); 772 | 773 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { 774 | mBuilder = new V28BuilderImpl(policy); 775 | 776 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 777 | mBuilder = new V26BuilderImpl(policy); 778 | 779 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { 780 | mBuilder = new V24BuilderImpl(policy); 781 | 782 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 783 | mBuilder = new V23BuilderImpl(policy); 784 | 785 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { 786 | mBuilder = new V18BuilderImpl(policy); 787 | 788 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { 789 | mBuilder = new V16BuilderImpl(policy); 790 | 791 | } else { 792 | mBuilder = new V14BuilderImpl(policy); 793 | } 794 | } 795 | 796 | public StrictMode.VmPolicy build() { 797 | return mBuilder.build(); 798 | } 799 | 800 | /** 801 | * Detect leaks of {@link Activity} subclasses. 802 | */ 803 | public Builder detectActivityLeaks() { 804 | mBuilder.detectActivityLeaks(); 805 | return this; 806 | } 807 | 808 | /** 809 | * Detect everything that's potentially suspect. 810 | *

811 | *

In the Honeycomb release this includes leaks of 812 | * SQLite cursors, Activities, and other closable objects 813 | * but will likely expand in future releases. 814 | */ 815 | public Builder detectAll() { 816 | mBuilder.detectAll(); 817 | return this; 818 | } 819 | 820 | /** 821 | * Detect any network traffic from the calling app which is not 822 | * wrapped in SSL/TLS. This can help you detect places that your app 823 | * is inadvertently sending cleartext data across the network. 824 | *

825 | * Using {@link #penaltyDeath()} or 826 | * {@link #penaltyDeathOnCleartextNetwork()} will block further 827 | * traffic on that socket to prevent accidental data leakage, in 828 | * addition to crashing your process. 829 | *

830 | * Using {@link #penaltyDropBox()} will log the raw contents of the 831 | * packet that triggered the violation. 832 | *

833 | * This inspects both IPv4/IPv6 and TCP/UDP network traffic, but it 834 | * may be subject to false positives, such as when STARTTLS 835 | * protocols or HTTP proxies are used. 836 | */ 837 | public Builder detectCleartextNetwork() { 838 | mBuilder.detectCleartextNetwork(); 839 | return this; 840 | } 841 | 842 | /** 843 | * Detect when this application exposes a {@code file://} 844 | * {@link Uri} to another app. 845 | *

846 | * This exposure is discouraged since the receiving app may not have 847 | * access to the shared path. For example, the receiving app may not 848 | * have requested the 849 | * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} runtime 850 | * permission, or the platform may be sharing the 851 | * {@link Uri} across user profile boundaries. 852 | *

853 | * Instead, apps should use {@code content://} Uris so the platform 854 | * can extend temporary permission for the receiving app to access 855 | * the resource. 856 | * 857 | * @see Intent#FLAG_GRANT_READ_URI_PERMISSION 858 | */ 859 | @SuppressWarnings("JavadocReference") 860 | public Builder detectFileUriExposure() { 861 | mBuilder.detectFileUriExposure(); 862 | return this; 863 | } 864 | 865 | /** 866 | * Detect when an {@link Closeable} or other 867 | * object with a explict termination method is finalized 868 | * without having been closed. 869 | *

870 | *

You always want to explicitly close such objects to 871 | * avoid unnecessary resources leaks. 872 | */ 873 | public Builder detectLeakedClosableObjects() { 874 | mBuilder.detectLeakedClosableObjects(); 875 | return this; 876 | } 877 | 878 | /** 879 | * Detect when a {@link BroadcastReceiver} or 880 | * {@link ServiceConnection} is leaked during {@link Context} 881 | * teardown. 882 | */ 883 | public Builder detectLeakedRegistrationObjects() { 884 | mBuilder.detectLeakedRegistrationObjects(); 885 | return this; 886 | } 887 | 888 | /** 889 | * Detect when an 890 | * {@link SQLiteCursor} or other 891 | * SQLite object is finalized without having been closed. 892 | *

893 | *

You always want to explicitly close your SQLite 894 | * cursors to avoid unnecessary database contention and 895 | * temporary memory leaks. 896 | */ 897 | public Builder detectLeakedSqlLiteObjects() { 898 | mBuilder.detectLeakedSqlLiteObjects(); 899 | return this; 900 | } 901 | 902 | /** 903 | * Crashes the whole process on violation. This penalty runs at the 904 | * end of all enabled penalties so you'll still get your logging or 905 | * other violations before the process dies. 906 | */ 907 | public Builder penaltyDeath() { 908 | mBuilder.penaltyDeath(); 909 | return this; 910 | } 911 | 912 | /** 913 | * Crashes the whole process when cleartext network traffic is 914 | * detected. 915 | * 916 | * @see #detectCleartextNetwork() 917 | */ 918 | public Builder penaltyDeathOnCleartextNetwork() { 919 | mBuilder.penaltyDeathOnCleartextNetwork(); 920 | return this; 921 | } 922 | 923 | /** 924 | * Crashes the whole process when a {@code file://} 925 | * {@link Uri} is exposed beyond this app. 926 | * 927 | * @see #detectFileUriExposure() 928 | */ 929 | public Builder penaltyDeathOnFileUriExposure() { 930 | mBuilder.penaltyDeathOnFileUriExposure(); 931 | return this; 932 | } 933 | 934 | /** 935 | * Enable detected violations log a stacktrace and timing data 936 | * to the {@link DropBoxManager DropBox} on policy 937 | * violation. Intended mostly for platform integrators doing 938 | * beta user field data collection. 939 | */ 940 | public Builder penaltyDropBox() { 941 | mBuilder.penaltyDropBox(); 942 | return this; 943 | } 944 | 945 | /** 946 | * Log detected violations to the system log. 947 | */ 948 | public Builder penaltyLog() { 949 | mBuilder.penaltyLog(); 950 | return this; 951 | } 952 | 953 | /** 954 | * Set an upper bound on how many instances of a class can be in memory 955 | * at once. Helps to prevent object leaks. 956 | * 957 | * @param klass Class for what apply instances limit 958 | * @param instanceLimit Max instances count 959 | */ 960 | public Builder setClassInstanceLimit(@NonNull Class klass, 961 | @IntRange(from = 0) int instanceLimit) { 962 | mBuilder.setClassInstanceLimit(klass, instanceLimit); 963 | return this; 964 | } 965 | 966 | /** 967 | * Detect when the calling application sends a content:// Uri to another app 968 | * without setting {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} or 969 | * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION}.

970 | * Forgetting to include one or more of these flags 971 | * when sending an intent is typically an app bug. 972 | */ 973 | public Builder detectContentUriWithoutPermission() { 974 | mBuilder.detectContentUriWithoutPermission(); 975 | return this; 976 | } 977 | 978 | /** 979 | * Detect any sockets in the calling app which have not been tagged 980 | * using {@link android.net.TrafficStats}. 981 | * Tagging sockets can help you investigate network usage inside your app, 982 | * such as a narrowing down heavy usage to a specific library or component. 983 | *

This currently does not detect sockets created in native code. 984 | */ 985 | public Builder detectUntaggedSockets() { 986 | mBuilder.detectUntaggedSockets(); 987 | return this; 988 | } 989 | 990 | /** 991 | * Detect reflective usage of APIs that are not part of the public Android SDK. 992 | *

993 | * Note that any non-SDK APIs that this processes accesses before this detection is enabled may not be detected. 994 | * To ensure that all such API accesses are detected, you should apply this policy as early as possible after process creation. 995 | */ 996 | public Builder detectNonSdkApiUsage() { 997 | mBuilder.detectNonSdkApiUsage(); 998 | return this; 999 | } 1000 | 1001 | /** 1002 | * Call {@link StrictMode.OnVmViolationListener#onVmViolation(Violation)} on every violation. 1003 | * 1004 | * @param executor This value must never be null. 1005 | * @param listener This value must never be null. 1006 | */ 1007 | public Builder penaltyListener(@NonNull Executor executor, 1008 | @NonNull OnVmViolationListener listener) { 1009 | mBuilder.penaltyListener(executor, listener); 1010 | return this; 1011 | } 1012 | 1013 | /** 1014 | * Permit reflective usage of APIs that are not part of the public Android SDK. 1015 | *

1016 | * Note that this only affects StrictMode, the underlying runtime may continue 1017 | * to restrict or warn on access to methods that are not part of the public SDK. 1018 | */ 1019 | public Builder permitNonSdkApiUsage() { 1020 | mBuilder.permitNonSdkApiUsage(); 1021 | return this; 1022 | } 1023 | 1024 | /** 1025 | * Detect any implicit reliance on Direct Boot automatic filtering of 1026 | * {@link android.content.pm.PackageManager} values. Violations are only triggered 1027 | * when implicit calls are made while the user is locked. 1028 | *

1029 | * Apps becoming Direct Boot aware need to carefully inspect each query site 1030 | * and explicitly decide which combination of flags they want to use: 1031 | * 1032 | *

1037 | */ 1038 | public Builder detectImplicitDirectBoot() { 1039 | mBuilder.detectImplicitDirectBoot(); 1040 | return this; 1041 | } 1042 | 1043 | /** 1044 | * Detect access to filesystem paths stored in credential 1045 | * protected storage areas while the user is locked. 1046 | *

1047 | * When a user is locked, credential protected storage is unavailable, 1048 | * and files stored in these locations appear to not exist, which can result 1049 | * in subtle app bugs if they assume default behaviors or empty states. 1050 | * Instead, apps should store data needed while a user is locked 1051 | * under device protected storage areas. 1052 | */ 1053 | public Builder detectCredentialProtectedWhileLocked() { 1054 | mBuilder.detectCredentialProtectedWhileLocked(); 1055 | return this; 1056 | } 1057 | } 1058 | 1059 | private interface BuilderImpl { 1060 | 1061 | String CATEGORY = "VmPolicy"; 1062 | 1063 | StrictMode.VmPolicy build(); 1064 | 1065 | void detectActivityLeaks(); 1066 | 1067 | void detectAll(); 1068 | 1069 | // Min SDK 23 1070 | void detectCleartextNetwork(); 1071 | 1072 | // Min SDK 18 1073 | void detectFileUriExposure(); 1074 | 1075 | void detectLeakedClosableObjects(); 1076 | 1077 | // Min SDK 16 1078 | void detectLeakedRegistrationObjects(); 1079 | 1080 | void detectLeakedSqlLiteObjects(); 1081 | 1082 | void penaltyDeath(); 1083 | 1084 | // Min SDK 23 1085 | void penaltyDeathOnCleartextNetwork(); 1086 | 1087 | // Min SDK 24 1088 | void penaltyDeathOnFileUriExposure(); 1089 | 1090 | void penaltyDropBox(); 1091 | 1092 | void penaltyLog(); 1093 | 1094 | void setClassInstanceLimit(@NonNull Class klass, @IntRange(from = 0) int instanceLimit); 1095 | 1096 | // Min SDK 26 1097 | void detectContentUriWithoutPermission(); 1098 | 1099 | // Min SDK 26 1100 | void detectUntaggedSockets(); 1101 | 1102 | // Min SDK 28 1103 | void detectNonSdkApiUsage(); 1104 | 1105 | // Min SDK 28 1106 | void penaltyListener(@NonNull Executor executor, @NonNull OnVmViolationListener listener); 1107 | 1108 | // Min SDK 28 1109 | void permitNonSdkApiUsage(); 1110 | 1111 | // Min SDK 29 1112 | void detectImplicitDirectBoot(); 1113 | 1114 | // Min SDK 29 1115 | void detectCredentialProtectedWhileLocked(); 1116 | } 1117 | 1118 | private static class V14BuilderImpl implements BuilderImpl { 1119 | 1120 | @NonNull 1121 | final StrictMode.VmPolicy.Builder mBuilder; 1122 | 1123 | V14BuilderImpl() { 1124 | mBuilder = new StrictMode.VmPolicy.Builder(); 1125 | } 1126 | 1127 | V14BuilderImpl(@NonNull StrictMode.VmPolicy policy) { 1128 | mBuilder = new StrictMode.VmPolicy.Builder(policy); 1129 | } 1130 | 1131 | @Override 1132 | public StrictMode.VmPolicy build() { 1133 | return mBuilder.build(); 1134 | } 1135 | 1136 | @Override 1137 | public void detectAll() { 1138 | mBuilder.detectAll(); 1139 | } 1140 | 1141 | @Override 1142 | public void detectCleartextNetwork() { 1143 | Utils.logUnsupportedFeature(CATEGORY, "Cleartext network"); 1144 | } 1145 | 1146 | @Override 1147 | public void detectFileUriExposure() { 1148 | Utils.logUnsupportedFeature(CATEGORY, "File uri exposure"); 1149 | } 1150 | 1151 | @Override 1152 | public void detectLeakedSqlLiteObjects() { 1153 | mBuilder.detectLeakedSqlLiteObjects(); 1154 | } 1155 | 1156 | @Override 1157 | public void detectLeakedRegistrationObjects() { 1158 | Utils.logUnsupportedFeature(CATEGORY, "Leaked registration objects"); 1159 | } 1160 | 1161 | @Override 1162 | public void penaltyDeath() { 1163 | mBuilder.penaltyDeath(); 1164 | } 1165 | 1166 | @Override 1167 | public void penaltyDeathOnCleartextNetwork() { 1168 | Utils.logUnsupportedFeature(CATEGORY, "Cleartext network"); 1169 | } 1170 | 1171 | @Override 1172 | public void penaltyDeathOnFileUriExposure() { 1173 | Utils.logUnsupportedFeature(CATEGORY, "Penalty death on file uri exposure"); 1174 | } 1175 | 1176 | @Override 1177 | public void penaltyDropBox() { 1178 | mBuilder.penaltyDropBox(); 1179 | } 1180 | 1181 | @Override 1182 | public void penaltyLog() { 1183 | mBuilder.penaltyLog(); 1184 | } 1185 | 1186 | @Override 1187 | public void detectActivityLeaks() { 1188 | mBuilder.detectActivityLeaks(); 1189 | } 1190 | 1191 | @Override 1192 | public void detectLeakedClosableObjects() { 1193 | mBuilder.detectLeakedClosableObjects(); 1194 | } 1195 | 1196 | @Override 1197 | public void setClassInstanceLimit(@NonNull Class klass, @IntRange(from = 0) int instanceLimit) { 1198 | mBuilder.setClassInstanceLimit(klass, instanceLimit); 1199 | } 1200 | 1201 | @Override 1202 | public void detectContentUriWithoutPermission() { 1203 | Utils.logUnsupportedFeature(CATEGORY, "Content uri without permission"); 1204 | } 1205 | 1206 | @Override 1207 | public void detectUntaggedSockets() { 1208 | Utils.logUnsupportedFeature(CATEGORY, "Untagged sockets"); 1209 | } 1210 | 1211 | @Override 1212 | public void detectNonSdkApiUsage() { 1213 | Utils.logUnsupportedFeature(CATEGORY, "Non SDK api usage"); 1214 | } 1215 | 1216 | @Override 1217 | public void penaltyListener(@NonNull Executor executor, 1218 | @NonNull OnVmViolationListener listener) { 1219 | Utils.logUnsupportedFeature(CATEGORY, "Penalty listener"); 1220 | } 1221 | 1222 | @Override 1223 | public void permitNonSdkApiUsage() { 1224 | Utils.logUnsupportedFeature(CATEGORY, "Non SDK api usage"); 1225 | } 1226 | 1227 | @Override 1228 | public void detectImplicitDirectBoot() { 1229 | Utils.logUnsupportedFeature(CATEGORY, "Implicit Direct Boot"); 1230 | } 1231 | 1232 | @Override 1233 | public void detectCredentialProtectedWhileLocked() { 1234 | Utils.logUnsupportedFeature(CATEGORY, "Credential Protected While Locked"); 1235 | } 1236 | } 1237 | 1238 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN) 1239 | private static class V16BuilderImpl extends V14BuilderImpl { 1240 | 1241 | V16BuilderImpl() { 1242 | } 1243 | 1244 | V16BuilderImpl(@NonNull StrictMode.VmPolicy policy) { 1245 | super(policy); 1246 | } 1247 | 1248 | @Override 1249 | public void detectLeakedRegistrationObjects() { 1250 | mBuilder.detectLeakedRegistrationObjects(); 1251 | } 1252 | } 1253 | 1254 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) 1255 | private static class V18BuilderImpl extends V16BuilderImpl { 1256 | 1257 | V18BuilderImpl() { 1258 | } 1259 | 1260 | V18BuilderImpl(@NonNull StrictMode.VmPolicy policy) { 1261 | super(policy); 1262 | } 1263 | 1264 | @Override 1265 | public void detectFileUriExposure() { 1266 | mBuilder.detectFileUriExposure(); 1267 | } 1268 | } 1269 | 1270 | @TargetApi(Build.VERSION_CODES.M) 1271 | private static class V23BuilderImpl extends V18BuilderImpl { 1272 | 1273 | V23BuilderImpl() { 1274 | } 1275 | 1276 | V23BuilderImpl(@NonNull StrictMode.VmPolicy policy) { 1277 | super(policy); 1278 | } 1279 | 1280 | @Override 1281 | public void detectCleartextNetwork() { 1282 | mBuilder.detectCleartextNetwork(); 1283 | } 1284 | 1285 | @Override 1286 | public void penaltyDeathOnCleartextNetwork() { 1287 | mBuilder.penaltyDeathOnCleartextNetwork(); 1288 | } 1289 | } 1290 | 1291 | @TargetApi(Build.VERSION_CODES.N) 1292 | private static class V24BuilderImpl extends V23BuilderImpl { 1293 | 1294 | V24BuilderImpl() { 1295 | } 1296 | 1297 | V24BuilderImpl(@NonNull StrictMode.VmPolicy policy) { 1298 | super(policy); 1299 | } 1300 | 1301 | @Override 1302 | public void penaltyDeathOnFileUriExposure() { 1303 | mBuilder.penaltyDeathOnFileUriExposure(); 1304 | } 1305 | } 1306 | 1307 | @TargetApi(Build.VERSION_CODES.O) 1308 | private static class V26BuilderImpl extends V24BuilderImpl { 1309 | 1310 | V26BuilderImpl() { 1311 | } 1312 | 1313 | V26BuilderImpl(@NonNull StrictMode.VmPolicy policy) { 1314 | super(policy); 1315 | } 1316 | 1317 | @Override 1318 | public void detectUntaggedSockets() { 1319 | mBuilder.detectUntaggedSockets(); 1320 | } 1321 | 1322 | @Override 1323 | public void detectContentUriWithoutPermission() { 1324 | mBuilder.detectContentUriWithoutPermission(); 1325 | } 1326 | } 1327 | 1328 | @TargetApi(Build.VERSION_CODES.P) 1329 | private static class V28BuilderImpl extends V26BuilderImpl { 1330 | 1331 | V28BuilderImpl() { 1332 | } 1333 | 1334 | V28BuilderImpl(@NonNull StrictMode.VmPolicy policy) { 1335 | super(policy); 1336 | } 1337 | 1338 | @Override 1339 | public void detectNonSdkApiUsage() { 1340 | mBuilder.detectNonSdkApiUsage(); 1341 | } 1342 | 1343 | @Override 1344 | public void permitNonSdkApiUsage() { 1345 | mBuilder.permitNonSdkApiUsage(); 1346 | } 1347 | 1348 | @Override 1349 | public void penaltyListener( 1350 | @NonNull Executor executor, 1351 | @NonNull final OnVmViolationListener listener 1352 | ) { 1353 | mBuilder.penaltyListener( 1354 | executor, 1355 | new StrictMode.OnVmViolationListener() { 1356 | 1357 | @Override 1358 | public void onVmViolation(Violation violation) { 1359 | listener.onVmViolation(violation); 1360 | } 1361 | } 1362 | ); 1363 | } 1364 | } 1365 | 1366 | @TargetApi(Build.VERSION_CODES.Q) 1367 | private static class V29BuilderImpl extends V26BuilderImpl { 1368 | 1369 | V29BuilderImpl() { 1370 | } 1371 | 1372 | V29BuilderImpl(@NonNull StrictMode.VmPolicy policy) { 1373 | super(policy); 1374 | } 1375 | 1376 | @Override 1377 | public void detectImplicitDirectBoot() { 1378 | mBuilder.detectImplicitDirectBoot(); 1379 | } 1380 | 1381 | @Override 1382 | public void detectCredentialProtectedWhileLocked() { 1383 | mBuilder.detectCredentialProtectedWhileLocked(); 1384 | } 1385 | } 1386 | } 1387 | } 1388 | --------------------------------------------------------------------------------