All Projects → androidbroadcast → StrictModeCompat

androidbroadcast / StrictModeCompat

Licence: Apache-2.0 license
Safety call StrctiMode API methods from newer Android SDK on old versions

Programming Languages

java
68154 projects - #9 most used programming language
kotlin
9241 projects
shell
77523 projects

Projects that are alternatives of or similar to StrictModeCompat

be-strict
add 'use strict' on the top of js files - don't forget to be strict with javascript!
Stars: ✭ 12 (-85.37%)
Mutual labels:  strict-mode
core2
The bare essentials of std::io for use in no_std. Alloc support is optional.
Stars: ✭ 67 (-18.29%)
Mutual labels:  compat
typescript-strict-plugin
Typescript plugin that allows turning on strict mode in specific files or directories.
Stars: ✭ 166 (+102.44%)
Mutual labels:  strict-mode
Strict-DataBinding
善用 DataBinding 彻底解决 “View 实例的 Null 安全一致性问题”
Stars: ✭ 84 (+2.44%)
Mutual labels:  strict-mode
Viewanimator
A fluent Android animation library
Stars: ✭ 2,656 (+3139.02%)
Mutual labels:  compat
Browser Compat Data
This repository contains compatibility data for Web technologies as displayed on MDN
Stars: ✭ 3,710 (+4424.39%)
Mutual labels:  compat
Eslint Plugin Compat
Lint the browser compatibility of your code
Stars: ✭ 2,743 (+3245.12%)
Mutual labels:  compat
angular-boilerplate
⛩️ Angular starter for enterprise-grade front-end projects, built under a clean architecture that helps to scale and maintain a fast workflow.
Stars: ✭ 158 (+92.68%)
Mutual labels:  strict-mode

Android Arsenal Maven Central

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.github.kirich1409:strict-mode-compat:30.2.0"

    // Kotlin Extensions
    implementation "com.github.kirich1409:strict-mode-compat-ktx: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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].