{"record":{"id":"30b7db7ee026dd9c","repo":"Tencent/matrix","slug":"interval-should-not-be-less-than-10s","errorCode":null,"errorMessage":"interval should NOT be less than 10s","messagePattern":"interval should NOT be less than 10s","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/lifecycle/owners/ProcessBackgroundStateOwner.kt","lineNumber":61,"sourceCode":" * NOTICE:\n *\n * [ForegroundServiceLifecycleOwner] is an optional StatefulOwner which is disabled by default and\n * can be enabled by [MatrixLifecycleConfig.enableFgServiceMonitor]\n * [OverlayWindowLifecycleOwner] is similar, which can be enabled by [MatrixLifecycleConfig.enableOverlayWindowMonitor]\n *\n * If the [ForegroundServiceLifecycleOwner] were disabled, this owner would start the timer checker\n * to check the ForegroundService states. If there were foreground Service launched after UI turned\n * background, the callback [IStateObserver.off] or [IMatrixLifecycleCallback.onForeground]\n * wouldn't be call until we call the [active] or the state of upstream Owner changes.\n * So do [OverlayWindowLifecycleOwner].\n */\nobject ProcessExplicitBackgroundOwner : StatefulOwner(), IBackgroundStatefulOwner {\n    private const val TAG = \"Matrix.background.Explicit\"\n\n    var maxCheckInterval = MAX_CHECK_INTERVAL\n        set(value) {\n            if (value < TimeUnit.SECONDS.toMillis(10)) {\n                throw IllegalArgumentException(\"interval should NOT be less than 10s\")\n            }\n            field = value\n            MatrixLog.i(TAG, \"set max check interval as $value\")\n        }\n\n    private val checkTask = object : TimerChecker(TAG, maxCheckInterval) {\n        override fun action(): Boolean {\n            val uiForeground by lazy { ProcessUIStartedStateOwner.active() }\n            val fgService by lazy { ForegroundServiceLifecycleOwner.hasForegroundService() }\n            val visibleWindow by lazy { OverlayWindowLifecycleOwner.hasOverlayWindow() }\n\n            if (uiForeground) {\n                MatrixLog.i(TAG, \"turn OFF for UI foreground\")\n                turnOff() // must be NOT in explicit background and do NOT need polling checker\n                return false\n            }\n\n            if (!fgService && !visibleWindow) {","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/lifecycle/owners/ProcessBackgroundStateOwner.kt#L43-L79","documentation":"ProcessExplicitBackgroundOwner detects background state with a periodic timer whose interval is maxCheckInterval. Intervals below 10 seconds would make the check too aggressive (waking the process constantly), so the setter throws IllegalArgumentException if the value is less than 10_000 ms.","triggerScenarios":"Assigning ProcessExplicitBackgroundOwner.maxCheckInterval = < 10000 (milliseconds), e.g. a config value in seconds written as milliseconds or a tuning attempt like 5000L.","commonSituations":"Confusing seconds and milliseconds in remote config; trying to make background detection more responsive by shrinking the interval below the supported floor.","solutions":["Set maxCheckInterval to at least 10_000L milliseconds (10s).","Convert seconds to milliseconds: TimeUnit.SECONDS.toMillis(seconds).","Keep the default MAX_CHECK_INTERVAL unless you need a longer interval."],"exampleFix":"// before\nProcessExplicitBackgroundOwner.maxCheckInterval = 5_000L // throws\n// after\nProcessExplicitBackgroundOwner.maxCheckInterval = 10_000L // 10s minimum","handlingStrategy":"validation","validationCode":"fun setExplicitInterval(ms: Long) {\n    require(ms >= TimeUnit.SECONDS.toMillis(10)) { \"interval must be >= 10s\" }\n    ProcessExplicitBackgroundOwner.maxCheckInterval = ms\n}","typeGuard":"null","tryCatchPattern":"try {\n    ProcessExplicitBackgroundOwner.maxCheckInterval = configuredMs\n} catch (e: IllegalArgumentException) {\n    MatrixLog.w(TAG, \"interval too small, using default\")\n}","preventionTips":["Store the config value in seconds and convert with TimeUnit.SECONDS.toMillis.","Clamp user/config values to >= 10_000L before assigning.","Keep the default MAX_CHECK_INTERVAL unless validated otherwise."],"tags":["android","config","argument-out-of-range"],"backgroundTag":"invalid-config-value","analyzedSha":"3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7","analyzedAt":"2026-09-08T08:01:39.722Z","contentChangedAt":"2026-09-08T08:01:39.722Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}