private IRecord getScheduleRecord() {
   List<IRecord> scheduleRecords = mBackupManager.getScheduleRecords();
   if (Util.isCollectionEmpty(scheduleRecords)) {
     return null;
   }
   final String preferSdCardPath = Util.getSdRootPathOnPreference(this);
   for (IRecord record : scheduleRecords) {
     String recordDir = ((RestorableRecord) record).getRecordRootDir();
     if (recordDir.startsWith(preferSdCardPath)) {
       return record;
     }
   }
   return scheduleRecords.get(0);
 }
Example #2
0
  private void backupSmsInternal(Context context, SmsBackupArgs args) {
    boolean ret = true;
    // 通知外部开始备份短信
    args.mHandler.sendEmptyMessage(SmsBackupMsg.MSG_BACKUP_START);

    // 获取短信
    Cursor cursor = getAllSmsFromDB(context);
    File file = new File(args.mBackupFilePath);
    try {
      if (cursor == null || cursor.getCount() <= 0) {
        Message.obtain(args.mHandler, SmsBackupMsg.MSG_SMS_COUNT_ZERO).sendToTarget();
        return;
      }

      // 写文件
      if (!writeSmsToDatFile(cursor, file, args.mHandler)) {
        // 写文件失败
        args.mHandler.sendEmptyMessage(SmsBackupMsg.MSG_BACKUP_ERROR_OCCUR);
        return;
      }
    } finally {
      if (cursor != null) {
        cursor.close();
      }
    }

    // 按照需求,如果用户取消,则删除文件
    synchronized (mLock) {
      if (mStopFlag) {
        file.delete();
        return;
      }
    }

    // 加密
    if (args.mNeedEncrypt && args.mEncryptPassword != null) {
      File tempFile = new File(file.getParent(), "sms.temp");
      String srcFileName = file.getAbsolutePath();
      if (!Util.encryFile(file, tempFile, args.mEncryptPassword)) {
        // 删除所有文件
        tempFile.delete();
        file.delete();
        ret = false;
      } else {
        // 删除源文件
        file.delete();
        tempFile.renameTo(new File(srcFileName));
        ret = true;
      }
    }

    if (!ret) {
      args.mHandler.sendEmptyMessage(SmsBackupMsg.MSG_BACKUP_ERROR_OCCUR);
      return;
    }

    args.mHandler.sendEmptyMessage(SmsBackupMsg.MSG_BACKUP_END);
  }
  public TutorialView(Context context, int layoutId, int spotlightResId, Rect bound) {
    super(context);
    LayoutInflater.from(context).inflate(layoutId, this, true);
    setBackgroundColor(0x00000000);
    mOriginalBound = bound;
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.XOR));
    mSpotlightBitmap = BitmapFactory.decodeResource(getResources(), spotlightResId);

    // 关闭硬件加速功能
    Util.setHardwareAccelerated(this, Util.LAYER_TYPE_SOFTWARE);
  }
 @Override
 public boolean loadIcon(Context context) {
   boolean ret = false;
   if (context != null) {
     mInitingIcon = true;
     Drawable icon = Util.loadIconFromPackageName(context, GOLAUNCHER_PACKAGE_NAME);
     if (icon != null) {
       setIcon(icon);
       ret = true;
     } else {
       ret = false;
     }
     mInitingIcon = false;
   }
   return ret;
 }
  private long calculateAllToMergeRecordSize() {
    //		List<IRecord> normalRecords = mBackupManager.getAllRestoreRecords();
    List<RecordItem> recordItemList = ((RecordItemListAdapter) mAdapter).getRecordItemList();
    if (Util.isCollectionEmpty(recordItemList)) {
      return 0;
    }

    long totalSize = 0;
    for (RecordItem recordItem : recordItemList) {
      if (recordItem != null && recordItem.isSelected) {
        totalSize += recordItem.record.getSpaceUsage();
      }
    }

    return totalSize;
  }