package com.example.iot_controlhost.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.example.iot_controlhost.utils.MMKVUtil;
import com.example.iot_controlhost.utils.MyUtil;
import com.example.iot_controlhost.utils.global.HardwareSetting;
import com.example.iot_controlhost.utils.global.RxTag;
import com.example.iot_controlhost.utils.log.MyLog;
import com.xuexiang.rxutil2.rxbus.RxBusUtils;

public class FrpStartReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context mContext, Intent intent) {
        String action = intent == null ? null : intent.getAction();
        if ("receiver_frp_version".equals(action)) {
            int frpVersion = intent.getIntExtra("version", 0);
            MyLog.frp("收到FRP版本：" + frpVersion);
            MMKVUtil.put(HardwareSetting.FRP_VERSION, frpVersion);
        } else if ("receiver_start_frp".equals(action)) {
            if (intent.getBooleanExtra("start_frp", false)) {
                MyLog.frp("收到启动FRP指令");
                MyUtil.relaunchFrp();
            }
        } else if ("receiver_frp_info".equals(action)) {
            String info = intent.getStringExtra("info");
            MyLog.frp(info);
            RxBusUtils.get().post(RxTag.UPDATE_MAIN_MSG, info);
        }
    }
}
