From 87af2f8087bf2a97efc96548f7bea15909a09360 Mon Sep 17 00:00:00 2001 From: problematicconsumer Date: Sat, 9 Sep 2023 16:02:33 +0330 Subject: [PATCH] Add android boot receiver --- .../com/hiddify/hiddify/bg/BootReceiver.kt | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 android/app/src/main/kotlin/com/hiddify/hiddify/bg/BootReceiver.kt diff --git a/android/app/src/main/kotlin/com/hiddify/hiddify/bg/BootReceiver.kt b/android/app/src/main/kotlin/com/hiddify/hiddify/bg/BootReceiver.kt new file mode 100644 index 00000000..028d16a9 --- /dev/null +++ b/android/app/src/main/kotlin/com/hiddify/hiddify/bg/BootReceiver.kt @@ -0,0 +1,30 @@ +package com.hiddify.hiddify.bg + +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import com.hiddify.hiddify.Settings +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext + +class BootReceiver : BroadcastReceiver() { + + override fun onReceive(context: Context, intent: Intent) { + when (intent.action) { + Intent.ACTION_BOOT_COMPLETED, Intent.ACTION_MY_PACKAGE_REPLACED -> { + } + + else -> return + } + GlobalScope.launch(Dispatchers.IO) { + if (Settings.startedByUser) { + withContext(Dispatchers.Main) { + BoxService.start() + } + } + } + } + +} \ No newline at end of file