MCPcopy Index your code
hub / github.com/androidbroadcast/StrictModeCompat

github.com/androidbroadcast/StrictModeCompat @30.2.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release 30.2.0 ↗ · + Follow
231 symbols 404 edges 13 files 59 documented · 26%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Android Arsenal

Android StrictMode Compat

Wrapper of StrictMode API that can be safely called on any version of Android. You must apply version of library for you project base on compileSdkVersion:

android {
    compileSdkVersion 30 // 30 is required minimum
}

dependencies {    
    implementation "com.kirich1409:strict-mode-compat:30.2.0"

    // Kotlin Extensions
    implementation "com.kirich1409:strict-mode-compat-kotlin:30.2.0"
}

Sample

build.gradle
android {
    buildTypes {
        debug {
            buildConfigField 'boolean', 'DEVELOPER_MODE', 'true'
        }

        release {
            buildConfigField 'boolean', 'DEVELOPER_MODE', 'false'
        }
    }
}
SampleApplication.java
public class SampleApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        if (BuildConfig.DEVELOPER_MODE) {
            StrictMode.ThreadPolicy threadPolicy = new StrictModeCompat.ThreadPolicy.Builder()
                        .detectResourceMismatches()
                        .detectCustomSlowCalls()
                        .detectUnbufferedIo()  // Available only on Android 8.0+
                        .penaltyLog()
                        .build();

            StrictMode.VmPolicy vmPolicy = new StrictModeCompat.VmPolicy.Builder()
                    .detectFileUriExposure()
                    .detectLeakedRegistrationObjects()
                    .detectCleartextNetwork()
                    .detectUntaggedSockets() // Available only on Android 8.0+
                    .detectContentUriWithoutPermission()  // Available only on Android 8.0+
                    .penaltyLog()
                    .build();

            StrictModeCompat.setPolicies(threadPolicy, vmPolicy);
        }
    }
}

Or you can use Kotlin extension and configure StrictModeCompat via DSL

SampleApplication.kt
class SampleApplicationKt : Application() {

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

                penalty {
                    log = true
                }
            }

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

                penalty {
                    log = true
                }
            }
        }
    }
}

License

Copyright 2017-2021 Kirill Rozov

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Extension points exported contracts — how you extend this code

OnVmViolationListener (Interface)
When StrictMode.VmPolicy.Builder#penaltyListener(Executor, StrictMode.OnVmViolationListener) is enabled, the lis [1 implementers]
strict-mode-compat/src/main/java/com/kirillr/strictmodehelper/StrictModeCompat.java
OnThreadViolationListener (Interface)
When StrictMode.ThreadPolicy.Builder#penaltyListener(Executor, StrictMode.OnThreadViolationListener) is enabled, [1 implementers]
strict-mode-compat/src/main/java/com/kirillr/strictmodehelper/StrictModeCompat.java

Core symbols most depended-on inside this repo

logUnsupportedFeature
called by 17
strict-mode-compat/src/main/java/com/kirillr/strictmodehelper/Utils.java
build
called by 8
strict-mode-compat/src/main/java/com/kirillr/strictmodehelper/StrictModeCompat.java
penaltyLog
called by 6
strict-mode-compat/src/main/java/com/kirillr/strictmodehelper/StrictModeCompat.java
detectAll
called by 4
strict-mode-compat/src/main/java/com/kirillr/strictmodehelper/StrictModeCompat.java
penaltyDeath
called by 4
strict-mode-compat/src/main/java/com/kirillr/strictmodehelper/StrictModeCompat.java
penaltyDropBox
called by 4
strict-mode-compat/src/main/java/com/kirillr/strictmodehelper/StrictModeCompat.java
penaltyListener
called by 4
strict-mode-compat/src/main/java/com/kirillr/strictmodehelper/StrictModeCompat.java
detectCustomSlowCalls
called by 3
strict-mode-compat/src/main/java/com/kirillr/strictmodehelper/StrictModeCompat.java

Shape

Method 195
Class 30
Function 3
Interface 3

Languages

Java86%
Kotlin14%

Modules by API surface

strict-mode-compat/src/main/java/com/kirillr/strictmodehelper/StrictModeCompat.java190 symbols
strict-mode-compat-kotlin/src/main/java/com/kirillr/strictmodehelper/kotlin/dsl/VmPolicyConfig.kt10 symbols
strict-mode-compat-kotlin/src/main/java/com/kirillr/strictmodehelper/kotlin/dsl/ThreadPolicyConfig.kt10 symbols
strict-mode-compat/src/main/java/com/kirillr/strictmodehelper/Utils.java3 symbols
strict-mode-compat-kotlin/src/main/java/com/kirillr/strictmodehelper/kotlin/dsl/StringMode.kt3 symbols
strict-mode-compat-kotlin/src/main/java/com/kirillr/strictmodehelper/kotlin/dsl/StrictModeConfig.kt3 symbols
sample/src/main/java/com/kirillr/application/MainActivity.java3 symbols
strict-mode-compat-kotlin/src/main/java/com/kirillr/strictmodehelper/kotlin/StrictModeCompat.kt2 symbols
sample/src/main/kotlin/SampleApplicationKt.kt2 symbols
sample/src/main/java/com/kirillr/application/SampleApplication.java2 symbols
strict-mode-compat-kotlin/src/main/java/com/kirillr/strictmodehelper/kotlin/dsl/VmPolicyDsl.kt1 symbols
strict-mode-compat-kotlin/src/main/java/com/kirillr/strictmodehelper/kotlin/dsl/ThreadPolicyDsl.kt1 symbols

For agents

$ claude mcp add StrictModeCompat \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact