@Override
 public void onAttach(Activity activity) {
   super.onAttach(activity);
   parseIntent(activity.getIntent());
   downLoadHelper = DownLoadHelper.getInstance(activity.getApplicationContext());
   dm = (DownloadManager) activity.getSystemService(Context.DOWNLOAD_SERVICE);
 }
  private int queryProductStatus(String productID) {
    final boolean notExist = wallPaperUnExist(productID);
    if (notExist) {
      return PRODUCT_STATUS_DOWNLOAD;
    }
    Cursor themeCursor = downLoadHelper.queryTheme(productID);
    if (themeCursor != null && themeCursor.getCount() > 0) {
      themeCursor.moveToFirst();
      mData.current_version_name =
          themeCursor.getString(themeCursor.getColumnIndex(PlugInColumns.VERSION_NAME));
      mData.current_version_code =
          themeCursor.getInt(themeCursor.getColumnIndex(PlugInColumns.VERSION_CODE));
      boolean isApplyed =
          themeCursor.getInt(themeCursor.getColumnIndex(PlugInColumns.IS_APPLY)) == 1
              ? true
              : false;
      themeCursor.close();
      if (mData.version_code > mData.current_version_code) {
        Cursor cursor = downLoadHelper.queryDownloadFile(productID);
        if (cursor != null && cursor.getCount() > 0) {
          cursor.moveToFirst();
          int downStatus =
              cursor.getInt(cursor.getColumnIndex(DownloadInfoColumns.DOWNLOAD_STATUS));
          if (downStatus == DownloadInfoColumns.DOWNLOAD_STATUS_DOWNLOADING) {
            downLoadID = cursor.getLong(cursor.getColumnIndex(DownloadInfoColumns.DOWNLOAD_ID));
            cursor.close();
            return PRODUCT_STATUS_DOWNLOADING;
          }
        }
        return PRODUCT_STATUS_NEED_UPDATE;
      }
      if (isApplyed) {
        return PRODUCT_STATUS_APPLIED;
      } else {
        return PRODUCT_STATUS_INSTALLED;
      }
    }
    if (themeCursor != null) themeCursor.close();

    Cursor cursor = downLoadHelper.queryDownloadFile(productID);
    if (cursor != null && cursor.getCount() > 0) {
      cursor.moveToFirst();
      int downStatus = cursor.getInt(cursor.getColumnIndex(DownloadInfoColumns.DOWNLOAD_STATUS));
      int current_version_code =
          cursor.getInt(cursor.getColumnIndex(DownloadInfoColumns.VERSION_CODE));
      long download_size = cursor.getLong(cursor.getColumnIndex(DownloadInfoColumns.SIZE));
      if (downStatus == DownloadInfoColumns.DOWNLOAD_STATUS_DOWNLOADING) {
        downLoadID = cursor.getLong(cursor.getColumnIndex(DownloadInfoColumns.DOWNLOAD_ID));
        cursor.close();
        return PRODUCT_STATUS_DOWNLOADING;
      } else if (downStatus == DownloadInfoColumns.DOWNLOAD_STATUS_COMPLETED) {
        String fileuri = cursor.getString(cursor.getColumnIndex(DownloadInfoColumns.LOCAL_PATH));
        File dFile = new File(URI.create(fileuri));
        if (dFile.exists() && dFile.length() == download_size) {
          if (mData != null) mData.localUrl = fileuri;
          if (mData.version_code > current_version_code) {
            // 服务器已经有新版本,本地缓存可以删除了
            downLoadHelper.deleteFile(productID, version_code);
            dFile.delete();
            return PRODUCT_STATUS_DOWNLOAD;
          } else {
            return PRODUCT_STATUS_DOWNLOADED;
          }
        }
        downLoadHelper.deleteFile(productID, version_code);
        cursor.close();
        //                }
      }
    }
    if (cursor != null) {
      cursor.close();
    }
    /*if (!notExist && PRODUCT_STATUS != PRODUCT_STATUS_DOWNLOADING) {
        return PRODUCT_STATUS_INSTALLED;
    } else */ if (mData.purchased) {
      return PRODUCT_STATUS_DOWNLOAD;
    } else {
      return PRODUCT_STATUS_PURCHASE;
    }
  }