package com.dowse.base.manager;

import android.content.Context;
import android.content.Intent;
import android.os.SystemClock;
import android.text.TextUtils;
import com.dowse.base.DSParamManager;
import com.dowse.base.IParamListener;
import com.dowse.base.data.DSDeviceCustomInfo;
import com.dowse.base.data.DSDeviceInfo;
import com.dowse.base.data.StaticIPInfo;
import com.dowse.base.log.DSLog;
import com.dowse.base.param.NetType;
import com.dowse.base.param.ParamType;
import com.dowse.base.param.device.DeviceConfigUtil;
import com.dowse.base.param.maintenance.MaintenanceParam;
import com.dowse.base.param.pic.ChannelPicConfig;
import com.dowse.base.param.pic.ChannelPicParam;
import com.dowse.base.param.pic.DSPicParam;
import com.dowse.base.param.video.ChannelConfig;
import com.dowse.base.param.video.ChannelOSD;
import com.dowse.base.param.video.ChannelOSDConfig;
import com.dowse.base.param.video.ChannelVideoConfig;
import com.dowse.base.param.video.ChannelVideoParam;
import com.dowse.base.param.video.DSOSDParam;
import com.dowse.base.param.video.DSVideoParam;
import com.dowse.base.util.APKUtil;
import com.dowse.base.util.ContextUtil;
import com.dowse.base.util.DeviceUtil;
import com.dowse.base.util.OtaUpdateUtil;
import com.google.gson.Gson;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

/* loaded from: ds_base_2.0.9_23030112.aar:classes.jar:com/dowse/base/manager/DSDeviceManager.class */
public class DSDeviceManager implements IParamListener {
    private static final String TAG = "DSDeviceManager";
    private static final String CAMERA_SERVER_PACKAGE_NAME = "com.dowse.app.camera.server";
    private static final String I1_PACKAGE_NAME = "com.dowse.i1app";
    private static final String I1_MASTER_PACKAGE_NAME = "com.dowse.i1master";
    private Context mContext;
    private boolean paramServiceInit;
    private List<IDeviceListener> listeners;

    public static DSDeviceManager getInstance() {
        return DSDeviceManagerHolder.instance;
    }

    @Override // com.dowse.base.IParamListener
    public void onInitResult(boolean result) {
        DSLog.d(TAG, "DSParamManager onInitResult result=" + result);
        this.paramServiceInit = result;
        notifyConnectChange(result);
    }

    /* loaded from: ds_base_2.0.9_23030112.aar:classes.jar:com/dowse/base/manager/DSDeviceManager$DSDeviceManagerHolder.class */
    private static class DSDeviceManagerHolder {
        public static final DSDeviceManager instance = new DSDeviceManager();

        private DSDeviceManagerHolder() {
        }
    }

    private DSDeviceManager() {
        this.mContext = null;
        this.paramServiceInit = false;
        this.listeners = null;
        this.mContext = ContextUtil.getApplication();
        this.listeners = new ArrayList();
        DSParamManager.getInstance().setInitListener(this);
    }

    public void setListener(IDeviceListener listener) {
        if (listener != null) {
            listener.onDeviceParamConnectChange(this.paramServiceInit);
            this.listeners.add(listener);
        }
    }

    public void delListener(IDeviceListener listener) {
        if ((this.listeners != null) & this.listeners.contains(listener)) {
            this.listeners.remove(listener);
        }
    }

    private void notifyConnectChange(boolean result) {
        for (IDeviceListener listener : this.listeners) {
            listener.onDeviceParamConnectChange(result);
        }
    }

    public DSDeviceInfo getDeviceInfo() {
        DSDeviceInfo deviceInfo = new DSDeviceInfo();
        deviceInfo.setModel(DeviceUtil.getModel());
        deviceInfo.setSerial_no(DeviceUtil.getSN());
        deviceInfo.setVersion(DeviceUtil.getSysVer());
        deviceInfo.setHard_ver(DeviceUtil.getHardVer());
        if (this.mContext != null) {
            deviceInfo.setCamera_v_code(APKUtil.getVersionCode(this.mContext, CAMERA_SERVER_PACKAGE_NAME));
            deviceInfo.setCamera_v_name(APKUtil.getVersionName(this.mContext, CAMERA_SERVER_PACKAGE_NAME));
            deviceInfo.setI1_v_code(APKUtil.getVersionCode(this.mContext, I1_PACKAGE_NAME));
            deviceInfo.setI1_v_name(APKUtil.getVersionName(this.mContext, I1_PACKAGE_NAME));
            deviceInfo.setI1_master_v_code(APKUtil.getVersionCode(this.mContext, I1_MASTER_PACKAGE_NAME));
            deviceInfo.setI1_master_v_name(APKUtil.getVersionName(this.mContext, I1_MASTER_PACKAGE_NAME));
        } else {
            DSLog.e(TAG, "getDeviceInfo mContext is null!!!");
        }
        deviceInfo.setSystemTime(System.currentTimeMillis());
        return deviceInfo;
    }

    public boolean setSystemTime(long time) {
        return SystemClock.setCurrentTimeMillis(time);
    }

    public StaticIPInfo getStaticIPInfo() {
        StaticIPInfo staticIP = new StaticIPInfo();
        if (this.mContext != null) {
            /*
            String ethName = NetUtil.getStaticEthName(this.mContext);
            if (!TextUtils.isEmpty(ethName)) {
                staticIP = NetUtil.getStaticIP(this.mContext, ethName);
            } else {
                DSLog.e(TAG, "getStaticIPInfo ethName:" + ethName);
            }
             */
        } else {
            DSLog.e(TAG, "getStaticIPInfo mContext is null!!!");
        }
        return staticIP;
    }

    public boolean setStaticIPInfo(StaticIPInfo staticIPInfo) {
        boolean result = false;
        DSLog.d(TAG, "setStaticIP StaticIPInfo msg=" + staticIPInfo.toString());

        if (staticIPInfo != null) {
            /*
            String ethName = NetUtil.getStaticEthName(this.mContext);
            if (!TextUtils.isEmpty(ethName)) {
                result = NetUtil.setStaticIP(this.mContext, ethName, staticIPInfo);
            } else {
                DSLog.e(TAG, "getStaticIPInfo ethName:" + ethName);
            }

             */
        }
        return result;
    }

    public MaintenanceParam getMaintenanceParam() {
        MaintenanceParam param = MaintenanceParam.getDefault(this.mContext);
        if (this.paramServiceInit && this.mContext != null) {
            String paramStr = DSParamManager.getInstance().getParam(ParamType.MAINTENANCE.getKey(), TAG);
            if (!TextUtils.isEmpty(paramStr)) {
                try {
                    param = (MaintenanceParam) new Gson().fromJson(paramStr, MaintenanceParam.class);
                } catch (Exception e) {
                    e.getMessage();
                    DSLog.d(TAG, "getMaintenanceParam msg=" + e.getMessage());
                }
            } else {
                DSParamManager.getInstance().setParam(ParamType.MAINTENANCE.getKey(), new Gson().toJson(param), TAG);
            }
        } else {
            DSLog.d(TAG, "getMaintenanceParam failed,reset default,paramServiceInit=" + this.paramServiceInit + ",mContext=" + this.mContext);
        }
        DSLog.d(TAG, "param=" + param.toString());
        return param;
    }

    public boolean setMaintenanceParam(int enable, String ip, int port, int sim) {
        boolean result = false;
        MaintenanceParam param = MaintenanceParam.getDefault(this.mContext);
        if (this.paramServiceInit && this.mContext != null) {
            String paramStr = DSParamManager.getInstance().getParam(ParamType.MAINTENANCE.getKey(), TAG);
            try {
                if (!TextUtils.isEmpty(paramStr)) {
                    param = (MaintenanceParam) new Gson().fromJson(paramStr, MaintenanceParam.class);
                }
                if (param != null) {
                    param.setEnable(enable);
                    param.setIp(ip);
                    param.setPort(port);
                    NetType curNetType = NetType.getNetType(sim);
                    String bindName = NetType.getBindEthName(this.mContext, sim);
                    if (curNetType != null && !TextUtils.isEmpty(bindName)) {
                        param.setNet(curNetType);
                        param.setNet_name(bindName);
                        result = DSParamManager.getInstance().setParam(ParamType.MAINTENANCE.getKey(), new Gson().toJson(param), TAG);
                    } else {
                        DSLog.e(TAG, "sim=" + sim + ",can't find netType,netType is null!!!use before = " + param.getNet());
                        return false;
                    }
                } else {
                    DSLog.d(TAG, "setMaintenanceParam failed,param is null!!!");
                }
            } catch (Exception e) {
                e.getMessage();
                DSLog.d(TAG, "setMaintenanceParam msg=" + e.getMessage());
            }
        } else {
            DSLog.d(TAG, "setMaintenanceParam failed,paramServiceInit=" + this.paramServiceInit + ",mContext=" + this.mContext);
        }
        DSLog.d(TAG, "set param=" + param.toString());
        return result;
    }

    public ChannelConfig getChannelConfig() {
        ChannelConfig param = DeviceConfigUtil.getDefaultChannelConfig();
        if (this.paramServiceInit && this.mContext != null) {
            String paramStr = DSParamManager.getInstance().getParam(ParamType.CHANNEL_CONFIG.getKey(), TAG);
            if (!TextUtils.isEmpty(paramStr)) {
                try {
                    param = (ChannelConfig) new Gson().fromJson(paramStr, ChannelConfig.class);
                } catch (Exception e) {
                    e.getMessage();
                    DSLog.d(TAG, "getChannelConfig msg=" + e.getMessage());
                }
            } else {
                DSParamManager.getInstance().setParam(ParamType.CHANNEL_CONFIG.getKey(), new Gson().toJson(param), TAG);
            }
        } else {
            DSLog.d(TAG, "getChannelConfig failed,reset default,paramServiceInit=" + this.paramServiceInit + ",mContext=" + this.mContext);
        }
        DSLog.d(TAG, "ChannelConfig = " + param.toString());
        return param;
    }

    public ChannelOSDConfig getChannelOSDConfig() {
        ChannelOSDConfig param = DeviceConfigUtil.getDefaultChannelOSDConfig();
        if (this.paramServiceInit && this.mContext != null) {
            String paramStr = DSParamManager.getInstance().getParam(ParamType.CHANNEL_OSD_CONFIG.getKey(), TAG);
            if (!TextUtils.isEmpty(paramStr)) {
                try {
                    param = (ChannelOSDConfig) new Gson().fromJson(paramStr, ChannelOSDConfig.class);
                } catch (Exception e) {
                    e.getMessage();
                    DSLog.d(TAG, "getChannelOSDConfig msg=" + e.getMessage());
                }
            } else {
                DSParamManager.getInstance().setParam(ParamType.CHANNEL_OSD_CONFIG.getKey(), new Gson().toJson(param), TAG);
            }
        } else {
            DSLog.d(TAG, "getChannelOSDConfig failed,reset default,paramServiceInit=" + this.paramServiceInit + ",mContext=" + this.mContext);
        }
        DSLog.d(TAG, "getChannelOSDConfig param=" + param.toString());
        return param;
    }

    public ChannelOSD getChannelOSD(int channel) {
        ChannelOSDConfig config = getChannelOSDConfig();
        ChannelOSD channelOSD = DeviceConfigUtil.getChannelOSD();
        if (config != null && config.getOsdList() != null) {
            for (DSOSDParam dsosdParam : config.getOsdList()) {
                if (dsosdParam.getChannel() == channel) {
                    channelOSD = dsosdParam.getChannelOSD();
                }
            }
        }
        return channelOSD;
    }

    public boolean setChannelOSD(int channel, ChannelOSD channelOSD) {
        List<DSOSDParam> datas;
        boolean result = false;
        int index = -1;
        ChannelOSDConfig config = getChannelOSDConfig();
        if (config != null && (datas = config.getOsdList()) != null) {
            int total = datas.size();
            int i = 0;
            while (true) {
                if (i < total) {
                    DSOSDParam param = datas.get(i);
                    if (param == null || param.getChannel() != channel) {
                        i++;
                    } else {
                        index = i;
                        break;
                    }
                } else {
                    break;
                }
            }
        }
        DSOSDParam osd = new DSOSDParam();
        osd.setChannelOSD(channelOSD);
        osd.setChannel(channel);
        if (index >= 0) {
            config.getOsdList().remove(index);
            config.getOsdList().add(osd);
        } else {
            if (config.getOsdList() == null) {
                config.setOsdList(new ArrayList());
            }
            config.getOsdList().add(osd);
        }
        if (this.paramServiceInit && this.mContext != null) {
            result = DSParamManager.getInstance().setParam(ParamType.CHANNEL_OSD_CONFIG.getKey(), new Gson().toJson(config), TAG);
        } else {
            DSLog.d(TAG, "setChannelOSD failed,reset default,paramServiceInit=" + this.paramServiceInit + ",mContext=" + this.mContext);
        }
        DSLog.d(TAG, "set param osd=" + osd.toString());
        return result;
    }

    public ChannelPicConfig getChannelPicConfig() {
        ChannelPicConfig param = DeviceConfigUtil.getDefaultChannelPicConfig();
        if (this.paramServiceInit && this.mContext != null) {
            String paramStr = DSParamManager.getInstance().getParam(ParamType.CHANNEL_PIC_CONFIG.getKey(), TAG);
            if (!TextUtils.isEmpty(paramStr)) {
                try {
                    param = (ChannelPicConfig) new Gson().fromJson(paramStr, ChannelPicConfig.class);
                } catch (Exception e) {
                    e.getMessage();
                    DSLog.d(TAG, "getChannelPicConfig msg=" + e.getMessage());
                }
            } else {
                DSParamManager.getInstance().setParam(ParamType.CHANNEL_PIC_CONFIG.getKey(), new Gson().toJson(param), TAG);
            }
        } else {
            DSLog.d(TAG, "getChannelPicConfig failed,reset default,paramServiceInit=" + this.paramServiceInit + ",mContext=" + this.mContext);
        }
        return param;
    }

    public ChannelPicParam getChannelPicParam(int channel) {
        ChannelPicConfig config = getChannelPicConfig();
        ChannelPicParam channelPicParam = DeviceConfigUtil.getChannelPicParam();
        if (config != null && config.getPicParams() != null) {
            for (DSPicParam picParam : config.getPicParams()) {
                if (picParam.getChannel() == channel) {
                    channelPicParam = picParam.getChannelPicParam();
                }
            }
        }
        return channelPicParam;
    }

    public boolean setChannelPicParam(int channel, ChannelPicParam channelPicParam) {
        List<DSPicParam> datas;
        boolean result = false;
        int index = -1;
        ChannelPicConfig config = getChannelPicConfig();
        if (config != null && (datas = config.getPicParams()) != null) {
            int total = datas.size();
            int i = 0;
            while (true) {
                if (i < total) {
                    DSPicParam param = datas.get(i);
                    if (param == null || param.getChannel() != channel) {
                        i++;
                    } else {
                        index = i;
                        break;
                    }
                } else {
                    break;
                }
            }
        }
        DSPicParam pic = new DSPicParam();
        pic.setChannel(channel);
        pic.setChannelPicParam(channelPicParam);
        if (index >= 0) {
            config.getPicParams().remove(index);
            config.getPicParams().add(pic);
        } else {
            if (config.getPicParams() == null) {
                config.setPicParams(new ArrayList());
            }
            config.getPicParams().add(pic);
        }
        if (this.paramServiceInit && this.mContext != null) {
            result = DSParamManager.getInstance().setParam(ParamType.CHANNEL_PIC_CONFIG.getKey(), new Gson().toJson(config), TAG);
        } else {
            DSLog.d(TAG, "setChannelPicParam failed,reset default,paramServiceInit=" + this.paramServiceInit + ",mContext=" + this.mContext);
        }
        return result;
    }

    public String getI1Param(String key) {
        String result = "";
        if (this.paramServiceInit && this.mContext != null) {
            result = DSParamManager.getInstance().getParam(key, TAG);
            DSLog.e(TAG, "key=" + key + ",json=" + result);
        } else {
            DSLog.d(TAG, "getI1Param failed,reset default,paramServiceInit=" + this.paramServiceInit + ",mContext=" + this.mContext);
        }
        return result;
    }

    public boolean setI1Param(String key, String i1Str) {
        boolean result = false;
        if (this.paramServiceInit && this.mContext != null) {
            result = DSParamManager.getInstance().setParam(key, i1Str, TAG);
        } else {
            DSLog.d(TAG, "setI1Param failed,reset default,paramServiceInit=" + this.paramServiceInit + ",mContext=" + this.mContext);
        }
        return result;
    }

    public boolean systemReboot() {
        boolean result = false;
        if (this.mContext != null) {
            Intent reboot = new Intent("android.intent.action.REBOOT");
            reboot.putExtra("nowait", 1);
            reboot.putExtra("interval", 1);
            reboot.putExtra("window", 0);
            this.mContext.sendBroadcast(reboot);
            result = true;
        } else {
            DSLog.d(TAG, "systemReboot failed,reset default,paramServiceInit=" + this.paramServiceInit + ",mContext=" + this.mContext);
        }
        return result;
    }

    public boolean installAPK(String filePath) {
        boolean result = false;
        if (this.mContext != null) {
            if (!TextUtils.isEmpty(filePath) && new File(filePath).exists()) {
                APKUtil.installAPK(this.mContext, filePath);
                result = true;
            } else {
                DSLog.d(TAG, "installAPK failed filePath=" + filePath + ",or not exists");
            }
        } else {
            DSLog.d(TAG, "systemReboot failed,reset default,paramServiceInit=" + this.paramServiceInit + ",mContext=" + this.mContext);
        }
        return result;
    }

    public boolean startAPK(String packageName) {
        boolean result = false;
        if (this.mContext != null) {
            APKUtil.startAPK(this.mContext, packageName);
            result = true;
        } else {
            DSLog.d(TAG, "startAPK failed,paramServiceInit=" + this.paramServiceInit + ",mContext=" + this.mContext);
        }
        return result;
    }

    public boolean stopAPK(String packageName) {
        boolean result = false;
        if (this.mContext != null) {
            APKUtil.stopAPK(this.mContext, packageName);
            result = true;
        } else {
            DSLog.d(TAG, "startAPK failed,paramServiceInit=" + this.paramServiceInit + ",mContext=" + this.mContext);
        }
        return result;
    }

    public boolean restoryFactory() {
        boolean result = false;
        if (this.mContext != null) {
            Intent intent = new Intent("android.intent.action.MASTER_CLEAR");
            intent.addFlags(16777216);
            this.mContext.sendBroadcast(intent);
            result = true;
        } else {
            DSLog.d(TAG, "systemReboot failed,reset default,paramServiceInit=" + this.paramServiceInit + ",mContext=" + this.mContext);
        }
        return result;
    }

    /* JADX WARN: Type inference failed for: r0v11, types: [com.dowse.base.manager.DSDeviceManager$1] */
    public boolean otaUpdate() {
        boolean result = false;
        if (this.mContext != null) {
            if (!TextUtils.isEmpty("/data/update.zip") && new File("/data/update.zip").exists()) {
                new Thread() { // from class: com.dowse.base.manager.DSDeviceManager.1
                    @Override // java.lang.Thread, java.lang.Runnable
                    public void run() {
                        OtaUpdateUtil otaUpdateUtil = new OtaUpdateUtil();
                        otaUpdateUtil.systemUpdate(DSDeviceManager.this.mContext, new OtaUpdateUtil.ProgressListener() { // from class: com.dowse.base.manager.DSDeviceManager.1.1
                            @Override // com.dowse.base.util.OtaUpdateUtil.ProgressListener
                            public void onProgress(int progress, String log) {
                                DSLog.d(DSDeviceManager.TAG, "progress:" + progress + ",log=" + log);
                            }
                        });
                    }
                }.start();
                result = true;
            } else {
                DSLog.d(TAG, "otaUpdate failed otaPath=/data/update.zip,or not exists");
            }
        } else {
            DSLog.d(TAG, "systemReboot failed,reset default,paramServiceInit=" + this.paramServiceInit + ",mContext=" + this.mContext);
        }
        return result;
    }

    public DSDeviceCustomInfo getDeviceCustomInfo() {
        DSDeviceCustomInfo param = DeviceConfigUtil.getDefaultDeviceCustomInfo();
        if (this.paramServiceInit && this.mContext != null) {
            String paramStr = DSParamManager.getInstance().getParam(ParamType.DEVICE_CUSTOM_INFO.getKey(), TAG);
            if (!TextUtils.isEmpty(paramStr)) {
                try {
                    param = (DSDeviceCustomInfo) new Gson().fromJson(paramStr, DSDeviceCustomInfo.class);
                } catch (Exception e) {
                    e.getMessage();
                    DSLog.d(TAG, "getDeviceCustomInfo msg=" + e.getMessage());
                }
            } else {
                DSParamManager.getInstance().setParam(ParamType.DEVICE_CUSTOM_INFO.getKey(), new Gson().toJson(param), TAG);
            }
        } else {
            DSLog.d(TAG, "getDeviceCustomInfo failed,reset default,paramServiceInit=" + this.paramServiceInit + ",mContext=" + this.mContext);
        }
        DSLog.d(TAG, "param=" + param.toString());
        return param;
    }

    public boolean setDeviceCustomInfo(DSDeviceCustomInfo info) {
        boolean result = false;
        DSDeviceCustomInfo param = DeviceConfigUtil.getDefaultDeviceCustomInfo();
        if (this.paramServiceInit && this.mContext != null) {
            String paramStr = DSParamManager.getInstance().getParam(ParamType.DEVICE_CUSTOM_INFO.getKey(), TAG);
            try {
                if (!TextUtils.isEmpty(paramStr)) {
                    param = (DSDeviceCustomInfo) new Gson().fromJson(paramStr, DSDeviceCustomInfo.class);
                }
                if (param != null) {
                    param.setManufacturerDate(info.getManufacturerDate());
                    param.setManufacturer(info.getManufacturer());
                    param.setDeviceModel(info.getDeviceModel());
                    param.setComponentId(info.getComponentId());
                    param.setDeviceName(info.getDeviceName());
                    result = DSParamManager.getInstance().setParam(ParamType.DEVICE_CUSTOM_INFO.getKey(), new Gson().toJson(param), TAG);
                } else {
                    DSLog.d(TAG, "setDeviceCustomInfo failed,param is null!!!");
                }
            } catch (Exception e) {
                e.getMessage();
                DSLog.d(TAG, "setDeviceCustomInfo msg=" + e.getMessage());
            }
        } else {
            DSLog.d(TAG, "setDeviceCustomInfo failed,paramServiceInit=" + this.paramServiceInit + ",mContext=" + this.mContext);
        }
        DSLog.d(TAG, "set param=" + param.toString());
        return result;
    }

    public ChannelVideoConfig getChannelVideoConfig() {
        ChannelVideoConfig param = DeviceConfigUtil.getDefaultChannelVideoConfig();
        if (this.paramServiceInit && this.mContext != null) {
            String paramStr = DSParamManager.getInstance().getParam(ParamType.CHANNEL_VIDEO_CONFIG.getKey(), TAG);
            if (!TextUtils.isEmpty(paramStr)) {
                try {
                    param = (ChannelVideoConfig) new Gson().fromJson(paramStr, ChannelVideoConfig.class);
                } catch (Exception e) {
                    e.getMessage();
                    DSLog.d(TAG, "getChannelVideoConfig msg=" + e.getMessage());
                }
            } else {
                DSParamManager.getInstance().setParam(ParamType.CHANNEL_VIDEO_CONFIG.getKey(), new Gson().toJson(param), TAG);
            }
        } else {
            DSLog.d(TAG, "getChannelVideoConfig failed,reset default,paramServiceInit=" + this.paramServiceInit + ",mContext=" + this.mContext);
        }
        return param;
    }

    public ChannelVideoParam getChannelVideoParam(int channel) {
        ChannelVideoConfig config = getChannelVideoConfig();
        ChannelVideoParam channelVideoParam = DeviceConfigUtil.getChannelVideoParam();
        if (config != null && config.getVideoParams() != null) {
            for (DSVideoParam videoParam : config.getVideoParams()) {
                if (videoParam.getChannel() == channel) {
                    channelVideoParam = videoParam.getChannelVideoParam();
                }
            }
        }
        return channelVideoParam;
    }

    public boolean setChannelVideoParam(int channel, ChannelVideoParam channelVideoParam) {
        List<DSVideoParam> datas;
        boolean result = false;
        int index = -1;
        ChannelVideoConfig config = getChannelVideoConfig();
        if (config != null && (datas = config.getVideoParams()) != null) {
            int total = datas.size();
            int i = 0;
            while (true) {
                if (i < total) {
                    DSVideoParam param = datas.get(i);
                    if (param == null || param.getChannel() != channel) {
                        i++;
                    } else {
                        index = i;
                        break;
                    }
                } else {
                    break;
                }
            }
        }
        DSVideoParam videoParam = new DSVideoParam();
        videoParam.setChannel(channel);
        videoParam.setChannelVideoParam(channelVideoParam);
        if (index >= 0) {
            config.getVideoParams().remove(index);
            config.getVideoParams().add(videoParam);
        } else {
            if (config.getVideoParams() == null) {
                config.setVideoParams(new ArrayList());
            }
            config.getVideoParams().add(videoParam);
        }
        if (this.paramServiceInit && this.mContext != null) {
            result = DSParamManager.getInstance().setParam(ParamType.CHANNEL_VIDEO_CONFIG.getKey(), new Gson().toJson(config), TAG);
        } else {
            DSLog.d(TAG, "setChannelVideoParam failed,reset default,paramServiceInit=" + this.paramServiceInit + ",mContext=" + this.mContext);
        }
        return result;
    }
}
