NVRDeviceChnInfoActivity.java 源代码


package main.NVR.Setting;

import activity.setting.ChooseDNSTypeActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import base.HiActivity;
import bean.MyCamera;
import com.hichip.NVR.content.HiChipNVRDefines;
import com.hichip.base.HiLog;
import com.hichip.callback.ICameraIOSessionCallback;
import com.hichip.campro.R;
import com.hichip.content.HiChipDefines;
import com.hichip.control.HiCamera;
import com.hichip.tools.Packet;
import com.xiaomi.mipush.sdk.Constants;
import common.Constant;
import common.ConstantCommand;
import common.HiDataValue;
import common.TitleView;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import liteos.ossetting.LiteOsSettingActivity;
import main.MainActivity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.apache.xmlbeans.XmlErrorCodes;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import utils.DialogUtilsCamHiPro;
import utils.HiLogcatUtil;
import utils.MyToast;

public class NVRDeviceChnInfoActivity extends HiActivity implements ICameraIOSessionCallback {
    private static final int CHOOSE_DNS_TYPE = 10010;
    private static final int GET_UPDATE_VERSION_DATA = 65536;
    private static final int GET_UPDATE_VERSION_NUM = 39321;
    private static final int HI_P2P_GET_CONFIGCAPIFO_KEYNAME_PARAM = 16792;
    private static String LiteOsDownloadUrl = "http://upgrade.hichip.net/goke_update.html";
    private static final int UPDATA_STATE_CHECKING = 1;
    private static final int UPDATA_STATE_NONE = 0;
    private HiChipDefines.HI_P2P_GET_DEV_INFO_EXT deviceInfo;
    private TextView device_name_tv;
    private ConstantCommand.HI_P2P_S_DEV_DNS_PARAM dns_param;
    private TextView dns_tv;
    private TextView dns_tv1;
    private TextView dns_tv2;
    private TextView dns_type;
    private TextView gateway_tv;
    private TextView gunware_version_tv;
    private ConstantCommand.HI_P2P_GET_UNITE_IPC_IMAGETYPE_PARAM imagetype_param;
    private TextView ip_address_tv;
    private boolean isLiteOsCheck;
    private boolean isSupport41AF;
    private boolean isSupportCustomDNS;
    private ImageView iv_4G_version;
    ImageView iv_conect_num;
    ImageView iv_device_type;
    private ImageView iv_dns1_dns2_line;
    ImageView iv_dns_2;
    private ImageView iv_dns_type_line;
    ImageView iv_ipaddr;
    ImageView iv_nettypeline;
    private ImageView iv_single_4G;
    ImageView iv_subnet_maskaddr;
    LinearLayout ll_gunversion;
    private LinearLayout ll_mic_version;
    LinearLayout ll_nvrhardversion;
    ImageView lm_gunversion;
    ImageView lm_nvrhardversion;
    private MyCamera mCamera;
    private HiChipNVRDefines.NVR_IPC_SYSINFO mIpcsysinfo;
    private TextView mTvdeviceType;
    private TextView network_state_tv;
    TextView nvrhardware_version_tv;
    private HiChipNVRDefines.PLATFORM_S_NVR_PARAM_REP nvrsys;
    private ProgressDialog progressDialog;
    private RelativeLayout rl_4G_version;
    RelativeLayout rl_conect_num;
    private RelativeLayout rl_dns_0;
    private RelativeLayout rl_dns_1;
    private RelativeLayout rl_dns_2;
    private RelativeLayout rl_dns_type;
    RelativeLayout rl_gateway;
    RelativeLayout rl_ipaddr;
    RelativeLayout rl_net_type;
    private RelativeLayout rl_single_4G;
    RelativeLayout rl_subnet_maskaddr;
    private TextView software_version_tv;
    private TextView subnet_mask_tv;
    private TextView tv_4G_version;
    private TextView tv_mic_date;
    private TextView tv_single_quality;
    TextView tv_upgrade_online_settings;
    private UpdateInfo updateInfo;
    private TextView user_connections_tv;
    private int updateStatus = 0;
    boolean isUpdate = false;
    private String redirectAddr = null;
    private String address = "";
    private String ptzNumber = "";
    public int chn = 0;
    private boolean nvrsinglechn = false;
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message message) {
            switch (message.what) {
                case HiDataValue.HANDLE_MESSAGE_SESSION_STATE:
                    NVRDeviceChnInfoActivity.this.handSession(message);
                    return;
                case HiDataValue.HANDLE_MESSAGE_RECEIVE_IOCTRL:
                    if (message.arg2 == 0) {
                        byte[] byteArray = message.getData().getByteArray("data");
                        int i = message.arg1;
                        if (i == 268435477) {
                            if (NVRDeviceChnInfoActivity.this.mCamera == null || NVRDeviceChnInfoActivity.this.mCamera.mNVRChildDev == null) {
                                return;
                            }
                            HiChipNVRDefines.PLATFORM_S_NVR_S_CHANNELSTATUS platform_s_nvr_s_channelstatus = new HiChipNVRDefines.PLATFORM_S_NVR_S_CHANNELSTATUS(byteArray);
                            if (platform_s_nvr_s_channelstatus.u32chn == NVRDeviceChnInfoActivity.this.chn) {
                                HiLogcatUtil.e(platform_s_nvr_s_channelstatus.status + "netword_abnormal:::" + NVRDeviceChnInfoActivity.this.mCamera.mNVRChildDev[NVRDeviceChnInfoActivity.this.chn].isIPCUPGRADE);
                                if (platform_s_nvr_s_channelstatus.status == 0) {
                                    NVRDeviceChnInfoActivity.this.handler.sendEmptyMessageDelayed(ConstantCommand.HI_P2P_GET_DEVICE_WORKING_MODE, 1000L);
                                }
                                if (platform_s_nvr_s_channelstatus.status != 1 || !NVRDeviceChnInfoActivity.this.mCamera.mNVRChildDev[NVRDeviceChnInfoActivity.this.chn].isIPCUPGRADE) {
                                    NVRDeviceChnInfoActivity.this.handler.sendEmptyMessageDelayed(ConstantCommand.HI_P2P_GET_DEVICE_WORKING_MODE, 1000L);
                                    return;
                                } else {
                                    NVRDeviceChnInfoActivity.this.handler.sendEmptyMessageDelayed(ConstantCommand.HI_P2P_SET_DEVICE_WORKING_MODE, 1000L);
                                    return;
                                }
                            }
                            return;
                        }
                        if (i == 268435496) {
                            if (NVRDeviceChnInfoActivity.this.mCamera == null || byteArray.length <= 4) {
                                return;
                            }
                            byte b = byteArray[0];
                            NVRDeviceChnInfoActivity.this.mCamera.mIsDiskStatus = b;
                            if (b != 5) {
                                if (NVRDeviceChnInfoActivity.this.mCamera.mIsDiskStatus != 3) {
                                    NVRDeviceChnInfoActivity.this.handler.sendEmptyMessageDelayed(ConstantCommand.HI_P2P_SET_DEVICE_WORKING_MODE, 1000L);
                                    return;
                                }
                                return;
                            }
                            NVRDeviceChnInfoActivity.this.startActivity(new Intent(NVRDeviceChnInfoActivity.this, (Class<?>) MainActivity.class), true);
                            return;
                        }
                        if (i != 268435505) {
                            return;
                        }
                        NVRDeviceChnInfoActivity.this.dismissjuHuaDialog();
                        if (byteArray.length >= 264) {
                            NVRDeviceChnInfoActivity.this.mIpcsysinfo = new HiChipNVRDefines.NVR_IPC_SYSINFO(byteArray);
                            HiLogcatUtil.e(NVRDeviceChnInfoActivity.this.mCamera.getUid() + "HI_NVR_P2P_PLATFORM_IPCSYSINFO" + NVRDeviceChnInfoActivity.this.mIpcsysinfo.u32Chn + "::" + NVRDeviceChnInfoActivity.this.mIpcsysinfo.s32SDStatus + "::" + NVRDeviceChnInfoActivity.this.mIpcsysinfo.s32SDFreeSpace + "::" + NVRDeviceChnInfoActivity.this.mIpcsysinfo.s32SDTotalSpace + ":aszWebVersion:" + Packet.getString(NVRDeviceChnInfoActivity.this.mIpcsysinfo.aszWebVersion) + ":aszSystemSoftVersion:" + Packet.getString(NVRDeviceChnInfoActivity.this.mIpcsysinfo.aszSystemSoftVersion) + ":aszSystemModel:" + Packet.getString(NVRDeviceChnInfoActivity.this.mIpcsysinfo.aszSystemModel) + ":aszSystemName:" + Packet.getString(NVRDeviceChnInfoActivity.this.mIpcsysinfo.aszSystemName) + ":aszStartDate:" + Packet.getString(NVRDeviceChnInfoActivity.this.mIpcsysinfo.aszStartDate));
                            if (NVRDeviceChnInfoActivity.this.mIpcsysinfo.u32Chn == NVRDeviceChnInfoActivity.this.chn) {
                                NVRDeviceChnInfoActivity.this.device_name_tv.setText(Packet.getString(NVRDeviceChnInfoActivity.this.mIpcsysinfo.aszSystemName));
                                NVRDeviceChnInfoActivity.this.mTvdeviceType.setText(Packet.getString(NVRDeviceChnInfoActivity.this.mIpcsysinfo.aszSystemModel));
                                NVRDeviceChnInfoActivity.this.software_version_tv.setText(Packet.getString(NVRDeviceChnInfoActivity.this.mIpcsysinfo.aszSystemSoftVersion));
                                NVRDeviceChnInfoActivity.this.handVersionAndView(null);
                                return;
                            }
                            return;
                        }
                        return;
                    }
                    NVRDeviceChnInfoActivity.this.dismissjuHuaDialog();
                    if (message.arg1 != 18433) {
                        return;
                    }
                    NVRDeviceChnInfoActivity nVRDeviceChnInfoActivity = NVRDeviceChnInfoActivity.this;
                    Toast.makeText(nVRDeviceChnInfoActivity, nVRDeviceChnInfoActivity.getString(R.string.update_fail), 1).show();
                    return;
                case NVRDeviceChnInfoActivity.GET_UPDATE_VERSION_NUM:
                    if (message.arg1 == 1) {
                        if (NVRDeviceChnInfoActivity.this.mCamera != null) {
                            NVRDeviceChnInfoActivity.this.mCamera.registerIOSessionListener(NVRDeviceChnInfoActivity.this);
                        }
                        if (!NVRDeviceChnInfoActivity.this.mCamera.getIsDevNVR()) {
                            if (NVRDeviceChnInfoActivity.this.isSupport41AF) {
                                NVRDeviceChnInfoActivity.this.handleDeviceInfoNew();
                                return;
                            } else {
                                NVRDeviceChnInfoActivity.this.handleDeviceInfo();
                                return;
                            }
                        }
                        if (!NVRDeviceChnInfoActivity.this.nvrsinglechn) {
                            if (NVRDeviceChnInfoActivity.this.nvrsys != null) {
                                NVRDeviceChnInfoActivity.this.handleDeviceInfoNew();
                                return;
                            }
                            return;
                        } else {
                            if (NVRDeviceChnInfoActivity.this.mIpcsysinfo == null || NVRDeviceChnInfoActivity.this.chn <= -1 || NVRDeviceChnInfoActivity.this.chn >= 32) {
                                return;
                            }
                            if (NVRDeviceChnInfoActivity.this.mCamera.mNVRChildDev[NVRDeviceChnInfoActivity.this.chn].isSupport41AF) {
                                NVRDeviceChnInfoActivity.this.handleDeviceInfoNew();
                                return;
                            } else {
                                NVRDeviceChnInfoActivity.this.handleDeviceInfo();
                                return;
                            }
                        }
                    }
                    NVRDeviceChnInfoActivity.this.updateStatus = 0;
                    NVRDeviceChnInfoActivity nVRDeviceChnInfoActivity2 = NVRDeviceChnInfoActivity.this;
                    MyToast.showToast(nVRDeviceChnInfoActivity2, nVRDeviceChnInfoActivity2.getString(R.string.tips_update_system_failed));
                    NVRDeviceChnInfoActivity.this.dismissjuHuaDialog();
                    return;
                case 65536:
                    NVRDeviceChnInfoActivity.this.updateStatus = 0;
                    NVRDeviceChnInfoActivity.this.showDialogOld();
                    return;
                case ConstantCommand.HI_P2P_GET_DEVICE_WORKING_MODE:
                    NVRDeviceChnInfoActivity.this.dismissjuHuaDialog();
                    NVRDeviceChnInfoActivity.this.dismissLoadDialog();
                    NVRDeviceChnInfoActivity.this.startActivity(new Intent(NVRDeviceChnInfoActivity.this, (Class<?>) MainActivity.class), true);
                    return;
                case ConstantCommand.HI_P2P_SET_DEVICE_WORKING_MODE:
                    NVRDeviceChnInfoActivity.this.dismissjuHuaDialog();
                    NVRDeviceChnInfoActivity.this.dismissLoadDialog();
                    HiDataValue.isNeedkillNoMain = false;
                    NVRDeviceChnInfoActivity.this.startActivity(new Intent(NVRDeviceChnInfoActivity.this, (Class<?>) MainActivity.class), true);
                    return;
                default:
                    return;
            }
        }
    };
    private List<UpdateInfo> mListUpdataInfo = new ArrayList();

    @Override
    protected int setLayoutId() {
        return R.layout.activity_device_nvrchn_info;
    }

    @Override
    protected void init(Bundle bundle) {
        String stringExtra = getIntent().getStringExtra(HiDataValue.EXTRAS_KEY_UID);
        this.chn = getIntent().getIntExtra("nvrposition", -1);
        this.nvrsinglechn = getIntent().getBooleanExtra("nvrsinglechn", false);
        Iterator<MyCamera> it = HiDataValue.CameraList.iterator();
        while (true) {
            if (!it.hasNext()) {
                break;
            }
            MyCamera next = it.next();
            if (stringExtra != null && stringExtra.equals(next.getUid())) {
                this.mCamera = next;
                if (next.getConnectState() == 4 && !this.mCamera.getIsDevNVR()) {
                    this.mCamera.sendIOCtrl(HiChipDefines.HI_P2P_GET_NET_PARAM, new byte[0]);
                }
            }
        }
        showjuHuaDialog();
        initView();
        if (this.mCamera.getIsDevNVR()) {
            if (!this.nvrsinglechn) {
                this.mCamera.sendIOCtrl(HiChipNVRDefines.HI_NVR_P2P_PLATFORM_GET_NVR_PARAM, new byte[0]);
                this.ll_nvrhardversion.setVisibility(0);
                this.lm_nvrhardversion.setVisibility(0);
                this.rl_net_type.setVisibility(8);
                this.rl_conect_num.setVisibility(8);
                this.iv_nettypeline.setVisibility(8);
            } else {
                new HiChipNVRDefines.NVR_IPC_SYSINFO(new byte[264]);
                this.mCamera.sendIOCtrl(HiChipNVRDefines.HI_NVR_P2P_PLATFORM_IPCSYSINFO, HiChipNVRDefines.NVR_IPC_SYSINFO.parseContent(this.chn));
                this.rl_net_type.setVisibility(8);
                this.rl_conect_num.setVisibility(8);
                this.rl_ipaddr.setVisibility(8);
                this.rl_subnet_maskaddr.setVisibility(8);
                this.rl_gateway.setVisibility(8);
                this.rl_dns_0.setVisibility(8);
                this.iv_nettypeline.setVisibility(8);
                this.iv_device_type.setVisibility(8);
                this.iv_conect_num.setVisibility(8);
                this.iv_ipaddr.setVisibility(8);
                this.iv_subnet_maskaddr.setVisibility(8);
                this.iv_dns_2.setVisibility(8);
            }
            if (this.mCamera.mNVRChildDev[this.chn].mIsDevOnvif) {
                return;
            }
            this.tv_upgrade_online_settings.setVisibility(0);
        }
    }

    private void initView() {
        TitleView titleView = (TitleView) findViewById(R.id.title_top);
        titleView.setTitle(getResources().getString(R.string.title_equipment_information));
        titleView.setButton(0);
        titleView.setNavigationBarButtonListener(new TitleView.NavigationBarButtonListener() {
            @Override
            public void OnNavigationButtonClick(int i) {
                if (i != 0) {
                    return;
                }
                NVRDeviceChnInfoActivity.this.finish();
            }
        });
        this.device_name_tv = (TextView) findViewById(R.id.device_name_tv);
        this.tv_mic_date = (TextView) findViewById(R.id.tv_mic_date);
        this.network_state_tv = (TextView) findViewById(R.id.network_state_tv);
        this.user_connections_tv = (TextView) findViewById(R.id.user_connections_tv);
        this.software_version_tv = (TextView) findViewById(R.id.software_version_tv);
        if (this.mCamera.getdevDual()) {
            this.gunware_version_tv = (TextView) findViewById(R.id.gunware_version_tv);
            if (this.mCamera.appGetCommandFunction(16873) && this.mCamera.appGetCommandFunction(HiChipDefines.HI_P2P_GET_DISPLAY_PARAM)) {
                this.mCamera.sendIOCtrl(16873, new byte[0]);
            } else {
                this.ll_gunversion.setVisibility(0);
                this.lm_gunversion.setVisibility(0);
            }
        }
        this.mTvdeviceType = (TextView) findViewById(R.id.device_type);
        this.tv_single_quality = (TextView) findViewById(R.id.tv_single_quality);
        this.tv_4G_version = (TextView) findViewById(R.id.tv_4G_version);
        this.rl_single_4G = (RelativeLayout) findViewById(R.id.rl_single_4G);
        this.rl_4G_version = (RelativeLayout) findViewById(R.id.rl_4G_version);
        this.iv_single_4G = (ImageView) findViewById(R.id.iv_single_4G);
        this.iv_4G_version = (ImageView) findViewById(R.id.iv_4G_version);
        this.ip_address_tv = (TextView) findViewById(R.id.ip_address_tv);
        this.subnet_mask_tv = (TextView) findViewById(R.id.subnet_mask_tv);
        this.gateway_tv = (TextView) findViewById(R.id.gateway_tv);
        this.dns_tv = (TextView) findViewById(R.id.dns_tv);
        this.ll_mic_version = (LinearLayout) findViewById(R.id.rl_mic_version);
        this.rl_dns_type = (RelativeLayout) findViewById(R.id.rl_dns_type);
        this.iv_dns_type_line = (ImageView) findViewById(R.id.iv_dns_type_line);
        this.dns_type = (TextView) findViewById(R.id.dns_type);
        this.dns_tv1 = (TextView) findViewById(R.id.dns_tv1);
        this.dns_tv2 = (TextView) findViewById(R.id.dns_tv2);
        this.rl_dns_0 = (RelativeLayout) findViewById(R.id.rl_dns_0);
        this.rl_dns_1 = (RelativeLayout) findViewById(R.id.rl_dns_1);
        this.rl_dns_2 = (RelativeLayout) findViewById(R.id.rl_dns_2);
        this.iv_dns1_dns2_line = (ImageView) findViewById(R.id.iv_dns1_dns2_line);
        MyCamera myCamera = this.mCamera;
        if (myCamera != null && myCamera.getIsLiteOs()) {
            this.ll_mic_version.setVisibility(0);
        }
        findViewById(R.id.rl_dev_name).setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public final boolean onLongClick(View view) {
                return NVRDeviceChnInfoActivity.this.lambda$initView$0$NVRDeviceChnInfoActivity(view);
            }
        });
        this.rl_dns_type.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(NVRDeviceChnInfoActivity.this, (Class<?>) ChooseDNSTypeActivity.class);
                intent.putExtra(HiDataValue.EXTRAS_KEY_UID, NVRDeviceChnInfoActivity.this.mCamera.getUid());
                if (NVRDeviceChnInfoActivity.this.dns_param != null) {
                    intent.putExtra("dns_type", NVRDeviceChnInfoActivity.this.dns_param.u32DnsDynFlag);
                    intent.putExtra("dns1", Packet.getString(NVRDeviceChnInfoActivity.this.dns_param.str_F_DNS_IP));
                    intent.putExtra("dns2", Packet.getString(NVRDeviceChnInfoActivity.this.dns_param.str_S_DNS_IP));
                }
                NVRDeviceChnInfoActivity.this.startActivityForResult(intent, 10010);
            }
        });
    }

    public boolean lambda$initView$0$NVRDeviceChnInfoActivity(View view) {
        MyCamera myCamera = this.mCamera;
        if (myCamera == null || !myCamera.getIsLiteOs()) {
            return false;
        }
        Toast.makeText(this, " liteos setting debug ", 1).show();
        LiteOsSettingActivity.isDebugModel = !LiteOsSettingActivity.isDebugModel;
        return false;
    }

    @Override
    public void receiveIOCtrlData(HiCamera hiCamera, int i, byte[] bArr, int i2) {
        if (hiCamera != this.mCamera) {
            return;
        }
        Bundle bundle = new Bundle();
        bundle.putByteArray("data", bArr);
        Message obtainMessage = this.handler.obtainMessage();
        obtainMessage.what = HiDataValue.HANDLE_MESSAGE_RECEIVE_IOCTRL;
        obtainMessage.obj = hiCamera;
        obtainMessage.arg1 = i;
        obtainMessage.arg2 = i2;
        obtainMessage.setData(bundle);
        this.handler.sendMessage(obtainMessage);
    }

    public void handSession(Message message) {
        if (message.arg1 != 4) {
            return;
        }
        this.mCamera.setReconnectTimes(10);
        dismissjuHuaDialog();
        this.mCamera.isSystemState = 0;
        startActivity(new Intent(this, (Class<?>) MainActivity.class));
    }

    @Override
    public void receiveSessionState(HiCamera hiCamera, int i) {
        if (hiCamera != this.mCamera) {
            return;
        }
        Message obtain = Message.obtain();
        obtain.what = HiDataValue.HANDLE_MESSAGE_SESSION_STATE;
        obtain.arg1 = i;
        this.handler.sendMessage(obtain);
    }

    @Override
    public void onResume() {
        super.onResume();
        MyCamera myCamera = this.mCamera;
        if (myCamera != null) {
            myCamera.registerIOSessionListener(this);
        }
    }

    @Override
    public void onPause() {
        super.onPause();
        MyCamera myCamera = this.mCamera;
        if (myCamera != null) {
            myCamera.unregisterIOSessionListener(this);
        }
    }

    public void handVersionAndView(String str) {
        int i;
        Log.i("tedu", " dev version: " + str);
        if (!this.mCamera.getIsDevNVR()) {
            this.isSupport41AF = this.mCamera.appGetCommandFunction(ConstantCommand.HI_P2P_SUPPORT_NEW_UPDATE);
            Log.i("tedu", " dev isSupportNewUpdate(41af): " + this.isSupport41AF);
            if (this.mCamera.mIsLiteOs) {
                if (!this.mCamera.getIsAPRunMode()) {
                    if (!this.mCamera.mNVRChildDev[this.chn].mIsDevOnvif) {
                        this.tv_upgrade_online_settings.setVisibility(0);
                    }
                    this.isLiteOsCheck = true;
                }
            } else if (this.isSupport41AF) {
                if (!this.mCamera.mNVRChildDev[this.chn].mIsDevOnvif) {
                    this.tv_upgrade_online_settings.setVisibility(0);
                }
            } else {
                update_old(str);
            }
        } else {
            int i2 = this.chn;
            if (i2 < 32 && i2 > -1) {
                HiLogcatUtil.e(this.mCamera.getUid() + ":::" + this.chn + "::" + this.mCamera.mNVRChildDev[this.chn].isSupport41AF + "::" + this.mCamera.mNVRChildDev[4].isSupport41AF);
            }
            if (!this.nvrsinglechn || ((i = this.chn) < 32 && i > -1 && this.mCamera.mNVRChildDev[this.chn].isSupport41AF)) {
                if (!this.mCamera.mNVRChildDev[this.chn].mIsDevOnvif) {
                    this.tv_upgrade_online_settings.setVisibility(0);
                }
            } else {
                HiChipNVRDefines.NVR_IPC_SYSINFO nvr_ipc_sysinfo = this.mIpcsysinfo;
                if (nvr_ipc_sysinfo != null) {
                    String str2 = null;
                    if (this.deviceInfo != null && nvr_ipc_sysinfo.aszSystemModel != null) {
                        str2 = Packet.getString(this.mIpcsysinfo.aszSystemModel);
                    }
                    if (str2 != null && str2.startsWith("C9") && str2.contains("Z0") && !this.mCamera.mNVRChildDev[this.chn].mIsDevOnvif) {
                        this.tv_upgrade_online_settings.setVisibility(0);
                    }
                    String[] split = Packet.getString(this.mIpcsysinfo.aszSystemSoftVersion).split("\\.");
                    if (split.length < 2) {
                        Log.e("tedu", "strings.length < 2");
                        return;
                    } else if (split[0].equals("V11") && split[1].equals("1") && split[2].equals("8") && !this.mCamera.mNVRChildDev[this.chn].mIsDevOnvif) {
                        this.tv_upgrade_online_settings.setVisibility(0);
                    }
                }
            }
        }
        this.tv_upgrade_online_settings.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                NVRDeviceChnInfoActivity.this.lambda$handVersionAndView$1$NVRDeviceChnInfoActivity(view);
            }
        });
    }

    public void lambda$handVersionAndView$1$NVRDeviceChnInfoActivity(View view) {
        if (this.updateStatus == 0) {
            showjuHuaDialog();
            checkUpdate();
        }
    }

    private void update_old(String str) {
        String[] split = str.split("\\.");
        if (split.length < 2) {
            Log.e("tedu", "strings.length < 2");
            return;
        }
        Log.e("tedu", this.mCamera.getChipVersion() + "");
        int chipVersion = this.mCamera.getChipVersion();
        if (chipVersion == 0) {
            if (split[0].equals("V11") && split[1].equals("1") && split[2].equals("8") && !this.mCamera.mNVRChildDev[this.chn].mIsDevOnvif) {
                this.tv_upgrade_online_settings.setVisibility(0);
                return;
            }
            return;
        }
        if (chipVersion != 1) {
            return;
        }
        String str2 = null;
        HiChipDefines.HI_P2P_GET_DEV_INFO_EXT hi_p2p_get_dev_info_ext = this.deviceInfo;
        if (hi_p2p_get_dev_info_ext != null && hi_p2p_get_dev_info_ext.aszSystemModel != null) {
            str2 = Packet.getString(this.deviceInfo.aszSystemModel);
        }
        if (str2 == null || !str2.startsWith("C9") || !str2.contains("Z0") || this.mCamera.mNVRChildDev[this.chn].mIsDevOnvif) {
            return;
        }
        this.tv_upgrade_online_settings.setVisibility(0);
    }

    private void checkUpdate() {
        new ThreadHttpResqust().start();
        this.updateStatus = 1;
    }

    public class UpdateInfo {
        String url;
        String ver;

        public UpdateInfo(String str, String str2) {
            this.url = str;
            this.ver = str2;
        }
    }

    public class ThreadHttpResqust extends Thread {
        public ThreadHttpResqust() {
        }

        @Override
        public void run() {
            try {
                HttpResponse execute = new DefaultHttpClient().execute(new HttpGet(NVRDeviceChnInfoActivity.LiteOsDownloadUrl));
                if (execute.getStatusLine().getStatusCode() == 200) {
                    String entityUtils = EntityUtils.toString(execute.getEntity());
                    HiLogcatUtil.e("version online:" + entityUtils);
                    try {
                        JSONArray jSONArray = new JSONObject(entityUtils).getJSONArray(XmlErrorCodes.LIST);
                        for (int i = 0; i < jSONArray.length(); i++) {
                            JSONObject jSONObject = jSONArray.getJSONObject(i);
                            NVRDeviceChnInfoActivity.this.mListUpdataInfo.add(new UpdateInfo(jSONObject.getString("url"), jSONObject.getString("ver")));
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    if (NVRDeviceChnInfoActivity.this.mListUpdataInfo.size() > 0) {
                        Message message = new Message();
                        message.what = NVRDeviceChnInfoActivity.GET_UPDATE_VERSION_NUM;
                        message.arg1 = 1;
                        NVRDeviceChnInfoActivity.this.handler.sendMessage(message);
                        return;
                    }
                }
                Message message2 = new Message();
                message2.what = NVRDeviceChnInfoActivity.GET_UPDATE_VERSION_NUM;
                message2.arg1 = 0;
                NVRDeviceChnInfoActivity.this.handler.sendMessage(message2);
            } catch (Exception unused) {
                Message message3 = new Message();
                message3.what = NVRDeviceChnInfoActivity.GET_UPDATE_VERSION_NUM;
                message3.arg1 = 0;
                NVRDeviceChnInfoActivity.this.handler.sendMessage(message3);
            }
        }
    }

    private static String getString(byte[] bArr) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < bArr.length && bArr[i] != 0; i++) {
            sb.append((char) bArr[i]);
        }
        return sb.toString();
    }

    public void handleDeviceInfoNew() {
        String string;
        Date date;
        if (!this.mCamera.getIsDevNVR()) {
            string = getString(this.mCamera.getDeciveInfo().aszSystemSoftVersion);
        } else if (this.nvrsinglechn) {
            string = Packet.getString(this.mIpcsysinfo.aszSystemSoftVersion);
        } else {
            string = Packet.getString(this.nvrsys.szSoftver);
        }
        Log.i("tedu", "handleDeviceInfoNew: softVersion: " + string);
        if (string.contains(Constants.ACCEPT_TIME_SEPARATOR_SERVER)) {
            String[] split = string.split(Constants.ACCEPT_TIME_SEPARATOR_SERVER);
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd", Locale.getDefault());
            try {
                Log.i("tedu", "dev date: " + split[1]);
                date = simpleDateFormat.parse(split[1]);
            } catch (ParseException e) {
                e.printStackTrace();
                date = null;
            }
            Iterator<UpdateInfo> it = this.mListUpdataInfo.iterator();
            Date date2 = null;
            while (true) {
                if (!it.hasNext()) {
                    break;
                }
                UpdateInfo next = it.next();
                if (next.ver.contains(Constants.ACCEPT_TIME_SEPARATOR_SERVER)) {
                    String[] split2 = next.ver.split(Constants.ACCEPT_TIME_SEPARATOR_SERVER);
                    try {
                        date2 = simpleDateFormat.parse(split2[1]);
                    } catch (ParseException e2) {
                        e2.printStackTrace();
                    }
                    if (split[0].equals(split2[0]) && date != null && date2 != null && date2.after(date)) {
                        Log.i("tedu", "new date: " + split2[1]);
                        Log.i("tedu", "find new version: " + next.ver + " ------- " + next.url);
                        this.updateInfo = next;
                        this.isUpdate = true;
                        break;
                    }
                }
            }
            if (this.isUpdate) {
                if (this.updateInfo == null) {
                    return;
                }
                if (!this.mCamera.getIsDevNVR()) {
                    this.redirectAddr = this.updateInfo.url + this.updateInfo.ver + ".exe";
                } else {
                    this.redirectAddr = this.updateInfo.url + this.updateInfo.ver + ".exe";
                }
                new ThreadCheckRedirect().start();
                return;
            }
            showDialogNew();
            this.updateStatus = 0;
        }
    }

    public void handleDeviceInfo() {
        String string;
        HiChipNVRDefines.NVR_IPC_SYSINFO nvr_ipc_sysinfo;
        if (!this.mCamera.getIsDevNVR()) {
            string = getString(this.mCamera.getDeciveInfo().aszSystemSoftVersion);
        } else {
            string = (!this.nvrsinglechn || (nvr_ipc_sysinfo = this.mIpcsysinfo) == null) ? "" : getString(nvr_ipc_sysinfo.aszSystemSoftVersion);
        }
        if (string.isEmpty() || string.length() < 3) {
            return;
        }
        if (this.isLiteOsCheck) {
            try {
                if (string.contains(Constants.ACCEPT_TIME_SEPARATOR_SERVER)) {
                    String str = string.split(Constants.ACCEPT_TIME_SEPARATOR_SERVER)[0];
                    int length = str.length() - 1;
                    while (true) {
                        if (length <= -1) {
                            length = 0;
                            break;
                        } else if (str.charAt(length) == 'V') {
                            break;
                        } else {
                            length--;
                        }
                    }
                    string = string.substring(length, string.length());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            if ((TextUtils.isEmpty(string) || !string.startsWith("V")) && string.contains("_V")) {
                string = string.substring(string.indexOf("_V") + 1, string.length());
            }
            Log.d("camhipro", string);
        }
        for (UpdateInfo updateInfo : this.mListUpdataInfo) {
            String[] split = updateInfo.ver.split("\\.");
            String[] split2 = string.split("\\.");
            Log.d("camhipro", Arrays.toString(split));
            Log.d("camhipro", Arrays.toString(split2));
            if (split.length == split2.length && split2.length == 5) {
                int i = 0;
                while (true) {
                    if (i >= split.length) {
                        break;
                    }
                    if (i == split.length - 1) {
                        String[] split3 = split[i].split(Constants.ACCEPT_TIME_SEPARATOR_SERVER);
                        String[] split4 = split2[i].split(Constants.ACCEPT_TIME_SEPARATOR_SERVER);
                        if ((split3.length >= 1 ? Integer.parseInt(split3[0]) : 0) > (split4.length >= 1 ? Integer.parseInt(split4[0]) : 0)) {
                            this.updateInfo = updateInfo;
                            this.isUpdate = true;
                        }
                    } else if (!split2[i].equals(split[i])) {
                        this.isUpdate = false;
                        break;
                    }
                    i++;
                }
            }
            if (this.isUpdate) {
                break;
            }
        }
        if (this.isUpdate) {
            if (this.updateInfo == null) {
                return;
            }
            this.redirectAddr = this.updateInfo.url + this.updateInfo.ver + ".exe";
            new ThreadCheckRedirect().start();
            return;
        }
        showDialogNew();
        this.updateStatus = 0;
    }

    public class ThreadCheckRedirect extends Thread {
        private ThreadCheckRedirect() {
        }

        @Override
        public void run() {
            Message message;
            int i;
            Socket socket;
            String readLine;
            Socket socket2 = null;
            String str = null;
            Socket socket3 = null;
            Socket socket4 = null;
            try {
                try {
                    UpdateInfo unused = NVRDeviceChnInfoActivity.this.updateInfo;
                    System.out.println("updateInfo:" + NVRDeviceChnInfoActivity.this.updateInfo);
                    System.out.println("updateInfo.url:" + NVRDeviceChnInfoActivity.this.updateInfo.url);
                    i = 80;
                    socket = new Socket();
                } catch (Throwable th) {
                    th = th;
                }
            } catch (UnknownHostException e) {
                e = e;
            } catch (IOException e2) {
                e = e2;
            }
            try {
                socket.setReuseAddress(true);
                Matcher matcher = Pattern.compile("(?<=//|)((\\w)+\\.)+\\w+(:\\d{0,5})?").matcher(NVRDeviceChnInfoActivity.this.updateInfo.url);
                if (matcher.find()) {
                    str = matcher.group();
                    System.out.println("host2:" + str);
                }
                if (str.contains(Constants.COLON_SEPARATOR)) {
                    String[] split = str.split(Constants.COLON_SEPARATOR);
                    String str2 = split[0];
                    int parseInt = Integer.parseInt(split[1]);
                    System.out.println("---00port:      " + split[0]);
                    System.out.println("---port:    " + parseInt);
                    str = str2;
                    i = parseInt;
                }
                socket.connect(new InetSocketAddress(str, i));
                DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
                String str3 = (((((("GET /" + NVRDeviceChnInfoActivity.this.updateInfo.ver + ".exe HTTP/1.1\r\n") + "Accept: */*\r\n") + "Accept-Language: zh-cn\r\n") + "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)\r\n") + "Host: " + str + "\r\n") + "Connection: Keep-Alive\r\n") + "\r\n";
                System.out.println("sendhead:" + str3);
                dataOutputStream.write(str3.getBytes());
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                while (true) {
                    readLine = bufferedReader.readLine();
                    System.out.println("in.readLine:" + readLine);
                    if (readLine.contains("HTTP/")) {
                        if (!readLine.contains("302") && !readLine.contains("301")) {
                            break;
                        } else {
                            System.out.println("------------ 301 302 Found----------------");
                        }
                    }
                    if (readLine.contains("Location:")) {
                        String trim = readLine.substring(9).trim();
                        System.out.println("1------------ newhttp----------------:" + trim);
                        NVRDeviceChnInfoActivity nVRDeviceChnInfoActivity = NVRDeviceChnInfoActivity.this;
                        readLine = readLine.substring(9).trim();
                        nVRDeviceChnInfoActivity.redirectAddr = readLine;
                        break;
                    }
                }
                dataOutputStream.close();
                bufferedReader.close();
                try {
                    socket.close();
                } catch (IOException unused2) {
                }
                message = new Message();
                socket2 = readLine;
            } catch (UnknownHostException e3) {
                e = e3;
                socket3 = socket;
                e.printStackTrace();
                if (socket3 != null) {
                    try {
                        socket3.close();
                    } catch (IOException unused3) {
                    }
                }
                message = new Message();
                socket2 = socket3;
                message.what = 65536;
                message.arg1 = 1;
                NVRDeviceChnInfoActivity.this.handler.sendMessage(message);
            } catch (IOException e4) {
                e = e4;
                socket4 = socket;
                e.printStackTrace();
                if (socket4 != null) {
                    try {
                        socket4.close();
                    } catch (IOException unused4) {
                    }
                }
                message = new Message();
                socket2 = socket4;
                message.what = 65536;
                message.arg1 = 1;
                NVRDeviceChnInfoActivity.this.handler.sendMessage(message);
            } catch (Throwable th2) {
                th = th2;
                socket2 = socket;
                if (socket2 != null) {
                    try {
                        socket2.close();
                    } catch (IOException unused5) {
                    }
                }
                Message message2 = new Message();
                message2.what = 65536;
                message2.arg1 = 1;
                NVRDeviceChnInfoActivity.this.handler.sendMessage(message2);
                throw th;
            }
            message.what = 65536;
            message.arg1 = 1;
            NVRDeviceChnInfoActivity.this.handler.sendMessage(message);
        }
    }

    private void showDialogNew() {
        dismissjuHuaDialog();
        MyCamera myCamera = this.mCamera;
        if (myCamera != null) {
            myCamera.unregisterIOSessionListener(this);
        }
        new DialogUtilsCamHiPro(this).title(getText(R.string.tips_warning)).message(getText(R.string.tip_system_update_new)).cancelText(getString(R.string.got_it)).build().show();
    }

    public void showDialogOld() {
        dismissjuHuaDialog();
        new DialogUtilsCamHiPro(this).title(getText(R.string.tips_warning)).message(getText(R.string.tip_system_update_old)).sureText(getString(R.string.sure)).cancelText(getString(R.string.cancel)).setSureOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                NVRDeviceChnInfoActivity.this.lambda$showDialogOld$2$NVRDeviceChnInfoActivity(view);
            }
        }).build().show();
    }

    public void lambda$showDialogOld$2$NVRDeviceChnInfoActivity(View view) {
        String str = this.redirectAddr;
        byte[] bArr = new byte[128];
        byte[] bytes = str.getBytes();
        System.arraycopy(bytes, 0, bArr, 0, bytes.length <= 128 ? bytes.length : 128);
        HiLog.v("dl:" + str);
        MyCamera myCamera = this.mCamera;
        if (myCamera != null) {
            myCamera.registerIOSessionListener(this);
        }
        showjuHuaDialog(false);
        this.mCamera.setReconnectTimes(20);
        if (!this.mCamera.getIsDevNVR()) {
            this.mCamera.sendIOCtrl(HiChipDefines.HI_P2P_SET_DOWNLOAD, HiChipDefines.HI_P2P_S_SET_DOWNLOAD.parseContent(0, bArr));
            return;
        }
        HiLogcatUtil.e(this.mCamera.getUid() + this.redirectAddr);
        if (!this.nvrsinglechn) {
            this.mCamera.sendIOCtrl(HiChipNVRDefines.HI_NVR_P2P_PLATFORM_NVR_UPGRADE, HiChipNVRDefines.PLATFORM_S_NVR_UPGRADE_REQ.parseContent(this.updateInfo.url.getBytes(), (this.updateInfo.ver + ".exe").getBytes()));
            return;
        }
        this.mCamera.sendIOCtrl(HiChipNVRDefines.HI_NVR_P2P_PLATFORM_IPCUPGRADE, HiChipNVRDefines.NVR_IPC_UPGRADE.parseContent(this.chn, this.redirectAddr.getBytes()));
        this.mCamera.mNVRChildDev[this.chn].isIPCUPGRADE = true;
    }

    private String getRightAddress(MyCamera myCamera, int i) {
        if (myCamera.getIsLiteOs()) {
            return Constant.LOW_POWER_ALARM_ADDRESS;
        }
        if ((i != 1 || (!myCamera.getUid().startsWith("W") && !myCamera.getUid().startsWith("T") && !myCamera.getUid().startsWith("U") && !myCamera.getUid().startsWith(Constant.X) && !myCamera.getUid().startsWith(Constant.Y) && !myCamera.getUid().startsWith("Z") && !myCamera.getUid().startsWith("S") && !myCamera.getUid().startsWith("M"))) && i == 0 && !myCamera.getUid().startsWith("W") && !myCamera.getUid().startsWith("T") && myCamera.getUid().startsWith("U")) {
        }
        return "120.24.179.113";
    }

    @Override
    public void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        if (i == 10010 && i2 == -1) {
            this.mCamera.sendIOCtrl(ConstantCommand.HI_P2P_GET_DEV_DNS_PARAM, new byte[0]);
        }
    }
}