mirror of
https://github.com/home-assistant/android.git
synced 2025-07-20 16:47:20 +00:00
Support strict intent matching (#5483)
* Enable some StrictMode flags in debug * Enable intentMatchingFlags flag * Add a flag to disable StrictMode * Enable strict mode for threading but log only
This commit is contained in:
@ -71,7 +71,8 @@
|
||||
android:networkSecurityConfig="@xml/network_security_config"
|
||||
android:enableOnBackInvokedCallback="true"
|
||||
android:localeConfig="@xml/locales_config"
|
||||
tools:ignore="GoogleAppIndexingWarning"
|
||||
android:intentMatchingFlags="enforceIntentFilter"
|
||||
tools:ignore="GoogleAppIndexingWarning,UnusedAttribute"
|
||||
tools:targetApi="tiramisu">
|
||||
|
||||
<!-- Start things like SensorWorker on device boot -->
|
||||
|
@ -11,6 +11,7 @@ import android.net.wifi.WifiManager
|
||||
import android.nfc.NfcAdapter
|
||||
import android.os.Build
|
||||
import android.os.PowerManager
|
||||
import android.os.StrictMode
|
||||
import android.telephony.TelephonyManager
|
||||
import androidx.core.content.ContextCompat
|
||||
import coil3.ImageLoader
|
||||
@ -63,6 +64,29 @@ open class HomeAssistantApplication : Application(), SingletonImageLoader.Factor
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S &&
|
||||
BuildConfig.DEBUG &&
|
||||
!BuildConfig.NO_STRICT_MODE
|
||||
) {
|
||||
StrictMode.setVmPolicy(
|
||||
StrictMode.VmPolicy.Builder()
|
||||
.detectIncorrectContextUse()
|
||||
.detectUnsafeIntentLaunch()
|
||||
.detectLeakedRegistrationObjects()
|
||||
.penaltyLog()
|
||||
.penaltyDeath()
|
||||
.build(),
|
||||
)
|
||||
|
||||
StrictMode.setThreadPolicy(
|
||||
StrictMode.ThreadPolicy.Builder()
|
||||
.detectAll()
|
||||
.penaltyLog()
|
||||
.build(),
|
||||
)
|
||||
}
|
||||
|
||||
// We should initialize the logger as early as possible in the lifecycle of the application
|
||||
Timber.plant(Timber.DebugTree())
|
||||
|
||||
|
@ -46,6 +46,9 @@ class AndroidApplicationConventionPlugin : Plugin<Project> {
|
||||
|
||||
versionName = project.version.toString()
|
||||
versionCode = System.getenv("VERSION_CODE")?.toIntOrNull() ?: 1
|
||||
|
||||
val noStrictMode = project.findProperty("noStrictMode")?.toString()?.ifEmpty { "true" }?.toBoolean() ?: false
|
||||
buildConfigField("Boolean", "NO_STRICT_MODE", noStrictMode.toString())
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
|
@ -34,3 +34,6 @@ android.experimental.enableScreenshotTest=true
|
||||
|
||||
# Uncomment to disable leak canary
|
||||
#noLeakCanary=true
|
||||
|
||||
# Uncomment to disable Strict Mode
|
||||
#noStrictMode=true
|
||||
|
@ -10,6 +10,7 @@ import android.net.wifi.WifiManager
|
||||
import android.nfc.NfcAdapter
|
||||
import android.os.Build
|
||||
import android.os.PowerManager
|
||||
import android.os.StrictMode
|
||||
import androidx.core.content.ContextCompat
|
||||
import dagger.hilt.android.HiltAndroidApp
|
||||
import io.homeassistant.companion.android.common.data.keychain.KeyChainRepository
|
||||
@ -35,6 +36,29 @@ open class HomeAssistantApplication : Application() {
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S &&
|
||||
BuildConfig.DEBUG &&
|
||||
!BuildConfig.NO_STRICT_MODE
|
||||
) {
|
||||
StrictMode.setVmPolicy(
|
||||
StrictMode.VmPolicy.Builder()
|
||||
.detectIncorrectContextUse()
|
||||
.detectUnsafeIntentLaunch()
|
||||
.detectLeakedRegistrationObjects()
|
||||
.penaltyLog()
|
||||
.penaltyDeath()
|
||||
.build(),
|
||||
)
|
||||
|
||||
StrictMode.setThreadPolicy(
|
||||
StrictMode.ThreadPolicy.Builder()
|
||||
.detectAll()
|
||||
.penaltyLog()
|
||||
.build(),
|
||||
)
|
||||
}
|
||||
|
||||
// We should initialize the logger as early as possible in the lifecycle of the application
|
||||
Timber.plant(Timber.DebugTree())
|
||||
|
||||
|
Reference in New Issue
Block a user