@Override
  public void init(Context context) {
    try {

      // todo 每次都请求routerip 是否恰当,待考虑
      mRouterIp = createRouterIp(context);

      if (mRouterIp == null || !isSupportRouter()) {
        return;
      }
      GetSysInfoAPI sysInfoAPI = new GetSysInfoAPI(mRouterIp);
      mSysInfo = sysInfoAPI.request();
      mSupportTD = true;
      if (mSupportTD) {
        AppConfig.logRemote(
            "skyworth********** remote service sucess" + System.currentTimeMillis());
      }

      if (mSysInfo != null) {
        isNetOK = mSysInfo.isNetOk;
        isDiscOk = mSysInfo.isDiskOk;
        isEverbinded = mSysInfo.isEverBinded;
        getVersion();
      }
    } catch (ConnectTimeoutException e) {
      AppConfig.logRemote("Remote service timeout------------");
    } catch (IOException e) {
      mSupportTD = false;
      UtilsConfig.LOGD("skyworth********** remote service failed" + System.currentTimeMillis());
    }
  }
  private List<FileItem> getTasklist(int complete, int pageindex, int pageCapacity) {
    List<FileItem> fileItems = new ArrayList<FileItem>();

    GetTaskListAPI taskListAPI =
        new GetTaskListAPI(mRouterIp, complete, pageindex, pageCapacity, mVersionCode, false);
    AppConfig.logRemote("router tddownload get tasklist");
    TaskList taskList = null;
    try {
      taskList = taskListAPI.request();
      if (taskList != null && taskList.tasks != null) {
        for (TaskList.Task task : taskList.tasks) {
          String path = task.filePath;
          String smbPath = getRouterSmbPath(path);
          AppConfig.logRemote("router tddownload file path is: " + smbPath);

          if (complete == GetTaskListAPI.TYPE_TASK_COMPLETED) {
            FileItem item = createFileItem(smbPath);
            if (item != null) {
              AppConfig.logRemote("router item: " + item.filePath + "  category:" + item.category);
              item.fileStatus = task.stat;
              if (item.category == FileCategory.DIR || item.category == FileCategory.VIDEO) {
                fileItems.add(item);
              }
            }
          } else {
            FileItem item = new FileItem();
            item.fileStatus = task.stat;
            item.filePath = task.filePath;
            fileItems.add(item);
          }
        }

        AppConfig.logRemote("router gettasklist size is: " + fileItems.size());

        return fileItems;
      }
    } catch (IOException e) {
      AppConfig.logRemote("[[XLRouterDownloadMgr]] getTaskList IOException:" + e.getMessage());
    }

    return null;
  }
  public static List<FileItem> filterItems(List<FileItem> list, Context context) {

    List<FileItem> result = new ArrayList<FileItem>();

    FileExploreHistoryManager fileExploreHistoryManager = new FileExploreHistoryManager(context);

    DeviceItem deviceItem = new DeviceItem();
    deviceItem.setType(DeviceItem.DeviceType.XL_ROUTER_TDDOWNLOAD);

    if (list != null) {

      for (FileItem fileItem : list) {

        fileItem.isNew = fileExploreHistoryManager.isFileNew(fileItem, deviceItem);

        if (fileItem.category == FileCategory.VIDEO) {
          result.add(fileItem);
        }

        if (fileItem.category == FileCategory.DIR) {
          AppConfig.logRemote("router file.getpaht is: " + fileItem.filePath);
          List<FileItem> childrens = getChildFiles(fileItem.filePath + File.separator, context);
          if (childrens != null && childrens.size() > 0) {

            for (int i = 0; i < childrens.size(); i++) {
              FileItem childItem = childrens.get(i);
              if (childItem.category == FileCategory.VIDEO
                  || childItem.category == FileCategory.DIR) {
                result.add(fileItem);
                break;
              }
            }
          }
        }
      }
    }

    AppConfig.logRemote("router tddownload after filter : " + result.size());

    return result;
  }
  public static FileItem createFileItem(String smbPath) {
    try {
      SmbFile smbFile = new SmbFile(smbPath);
      if (!smbFile.exists()) {
        return null;
      }

      FileItem item = new FileItem();
      String fileName = smbFile.getName();
      String filePath = smbFile.getCanonicalPath();

      if (smbFile.isDirectory()) {
        fileName = fileName.substring(0, fileName.length() - 1);
        item.category = FileCategory.DIR;
        item.fileSize = 0;
      } else if (smbFile.isFile()) {
        item.category = FileCategoryHelper.getFileCategoryByName(fileName);
        item.fileSize = smbFile.getContentLength();
      }

      item.fileName = fileName;
      item.filePath = filePath;
      item.lastModifyTime = smbFile.getLastModified();
      item.canRead = smbFile.canRead();
      item.canWrite = smbFile.canWrite();
      item.cid = "";

      return item;

    } catch (MalformedURLException e) {
      AppConfig.logRemote(
          "[[XlrounterDownloadMgr]] createFileItem MalformedURLException:" + e.getMessage());
    } catch (SmbException e) {
      AppConfig.logRemote("[[XlrounterDownloadMgr]] createFileItem SmbException:" + e.getMessage());
    }

    return null;
  }
  public static List<FileItem> getChildFiles(String smbPath, Context context) {
    try {
      List<FileItem> list = new ArrayList<FileItem>();

      SmbFile smbRootFile = new SmbFile(smbPath);

      if (!smbRootFile.exists()) {
        return null;
      }

      SmbFile[] fileList = smbRootFile.listFiles();
      if (fileList == null || fileList.length == 0) {
        return null;
      }

      FileExploreHistoryManager fileExploreHistoryManager = new FileExploreHistoryManager(context);

      DeviceItem deviceItem = new DeviceItem();
      deviceItem.setType(DeviceItem.DeviceType.XL_ROUTER_TDDOWNLOAD);

      for (SmbFile smbFile : fileList) {
        FileItem item = new FileItem();
        String fileName = smbFile.getName();
        String filePath = smbFile.getCanonicalPath();
        item.filePath = filePath;
        item.lastModifyTime = smbFile.getLastModified();
        item.canRead = smbFile.canRead();
        item.canWrite = smbFile.canWrite();
        try {
          BufferedInputStream bis = new BufferedInputStream(new SmbFileInputStream(smbFile));
          String cid = CidUtil.queryCid(bis, smbFile.length());
          if (!TextUtils.isEmpty(cid)) {
            item.cid = cid;
          } else {
            item.cid = "";
          }
        } catch (SmbException e) {
        } catch (MalformedURLException e) {
        } catch (UnknownHostException e) {
        }

        if (smbFile.isDirectory()) {
          fileName = fileName.substring(0, fileName.length() - 1);
          item.fileName = fileName;

          item.category = FileCategory.DIR;
          item.fileSize = 0;

          item.isNew = fileExploreHistoryManager.isFileNew(item, deviceItem);

          list.add(item);
        } else if (smbFile.isFile()) {
          item.category = FileCategoryHelper.getFileCategoryByName(fileName);
          item.fileSize = smbFile.getContentLength();
          item.fileName = fileName;

          if (item.category == FileCategory.VIDEO) {
            item.isNew = fileExploreHistoryManager.isFileNew(item, deviceItem);
            list.add(item);
          }
        }
      }

      return list;

    } catch (MalformedURLException e) {
      AppConfig.logRemote(
          "[[XlrounterDownloadMgr]] createFileItem MalformedURLException:" + e.getMessage());
    } catch (SmbException e) {
      AppConfig.logRemote("[[XlrounterDownloadMgr]] createFileItem SmbException:" + e.getMessage());
    }

    return null;
  }