package me.eternal.purrfectsnap.core.features.impl.experiments

import android.content.Intent
import me.eternal.purrfectsnap.core.features.Feature
import me.eternal.purrfectsnap.core.util.hook.HookStage
import me.eternal.purrfectsnap.core.util.hook.hook

class PreventForcedLogout : Feature("Prevent Forced Logout") {
    override fun init() {
        if (!context.config.experimental.preventForcedLogout.get()) return
        findClass("com.snap.identity.service.ForcedLogoutBroadcastReceiver").hook("onReceive", HookStage.BEFORE) { param ->
            val intent = param.arg<Intent>(1)
            if (!intent.getBooleanExtra("forced", false)) return@hook
            context.log.verbose("Prevent forced logout, reason=${intent.getStringExtra("reason")}")
            param.setResult(null)
        }
    }
}