package com.xypower.mpmaster.sms;

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

import com.dev.devapi.api.SysApi;

/**
 * 短信发送的监听广播
 * 从Android 4.4（API 19）开始，由于安全和隐私原因，不再允许应用程序静态注册监听短信发送状态的广播。
 *
 * @author jingjing
 */
public class SmsSendReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (SimUtil.SMS_SEND_ACTION.equals(action)) {
            String type = intent.getStringExtra(SimUtil.SMSTYPE);
            if (type.contains(SmsTypeEnum.REBOOT1.value())) {
                SysApi.reboot(context);
            } else if (type.contains(SmsTypeEnum.REBOOT2.value())) {
                SysApi.reboot(context);
            } else if (type.contains(SmsTypeEnum.SET_YW_SCHEDULE.value())) {
                UpdateSysConfigUtil.restartMasterApp(context);
            } else if (type.contains(SmsTypeEnum.SET_OPERATE.value())) {
                UpdateSysConfigUtil.restartMasterApp(context);
            } else if (type.contains(SmsTypeEnum.SET_OPERATE_URL.value())) {
                UpdateSysConfigUtil.restartMasterApp(context);
            } else if (type.contains(SmsTypeEnum.SET_CMDID.value())) {
                UpdateSysConfigUtil.restartApp(context);
            } else if (type.contains(SmsTypeEnum.SET_IP.value())) {
                UpdateSysConfigUtil.restartApp(context);
            } else if (type.contains(SmsTypeEnum.SET_OSD.value())) {
                UpdateSysConfigUtil.restartApp(context);
            } else if (type.contains(SmsTypeEnum.SET_PHOTO_SCHEDULE_LIST.value())) {
                UpdateSysConfigUtil.restartApp(context);
            } else if (type.contains(SmsTypeEnum.SET_RESOLUTION.value())) {
                UpdateSysConfigUtil.restartApp(context);
            } else if (type.contains(SmsTypeEnum.SET_HEART.value())) {
                UpdateSysConfigUtil.restartApp(context);
            } else if (type.contains(SmsTypeEnum.SET_TP.value())) {
                UpdateSysConfigUtil.restartApp(context);
            } else if (type.contains(SmsTypeEnum.SET_PACKAGE.value())) {
                UpdateSysConfigUtil.restartApp(context);
            }
        }
    }
}