From eab9f50cfd35db476944269dfbe86760bef3850f Mon Sep 17 00:00:00 2001 From: Tamim Hossain <132823494+CodeWithTamim@users.noreply.github.com> Date: Tue, 5 Nov 2024 15:57:51 +0600 Subject: [PATCH] Refactor BootReceiver for improved null handling and readability (#3876) Refactored `BootReceiver` to simplify null checks and conditional structure. Combined context and intent checks into a single early return and refactored logic for `decodeStartOnBoot` and `getSelectServer` to improve readability. --- .../kotlin/com/v2ray/ang/receiver/BootReceiver.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/receiver/BootReceiver.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/receiver/BootReceiver.kt index 7f2eff1e..acc86730 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/receiver/BootReceiver.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/receiver/BootReceiver.kt @@ -8,11 +8,11 @@ import com.v2ray.ang.service.V2RayServiceManager class BootReceiver : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { - if (Intent.ACTION_BOOT_COMPLETED == intent?.action && MmkvManager.decodeStartOnBoot()) { - if (MmkvManager.getSelectServer().isNullOrEmpty()) { - return - } - V2RayServiceManager.startV2Ray(context!!) - } + //Check if context is not null and action is the one we want + if (context == null || intent?.action != Intent.ACTION_BOOT_COMPLETED) return + //Check if flag is true and a server is selected + if (!MmkvManager.decodeStartOnBoot() || MmkvManager.getSelectServer().isNullOrEmpty()) return + //Start v2ray + V2RayServiceManager.startV2Ray(context) } -} \ No newline at end of file +}