コード例 #1
0
 /**
  * Updates the state but do not notify TransferService to refresh its transfer record list.
  * Therefore, only TransferObserver knows the state change of the transfer record. If the new
  * state is STATE_FAILED, we need to check the original state, because "pause", "cancel" and
  * "disconnect network" actions may also cause failure message of the threads, but these are not
  * actual failure of transfers.
  *
  * @param id The id of the transfer.
  * @param state The new state of the transfer.
  * @return Number of rows updated.
  */
 public int updateState(int id, TransferState state) {
   ContentValues values = new ContentValues();
   values.put(TransferTable.COLUMN_STATE, state.toString());
   if (TransferState.FAILED.equals(state)) {
     return transferDBBase.update(
         getRecordUri(id),
         values,
         TransferTable.COLUMN_STATE + " not in (?,?,?,?,?) ",
         new String[] {
           TransferState.COMPLETED.toString(),
           TransferState.PENDING_NETWORK_DISCONNECT.toString(),
           TransferState.PAUSED.toString(),
           TransferState.CANCELED.toString(),
           TransferState.WAITING_FOR_NETWORK.toString()
         });
   } else {
     return transferDBBase.update(getRecordUri(id), values, null, null);
   }
 }
コード例 #2
0
 /**
  * Gets the Uri of the records that have the given state.
  *
  * @param state The state of transfers
  * @return The Uri that is used to query transfer records with the given state.
  */
 public Uri getStateUri(TransferState state) {
   return Uri.parse(transferDBBase.getContentUri() + "/state/" + state.toString());
 }
コード例 #3
0
 /**
  * Updates the state and also notify TransferService to refresh its transfer record list. The
  * method is called by TransferUtility, more typically, by applications to perform "pause" or
  * "resume" actions, so it needs to explicitly notify the Service after updating the database.
  *
  * @param id The id of the transfer.
  * @param state The new state of the transfer.
  * @return Number of rows updated.
  */
 public int updateStateAndNotifyUpdate(int id, TransferState state) {
   ContentValues values = new ContentValues();
   values.put(TransferTable.COLUMN_STATE, state.toString());
   return transferDBBase.update(
       transferDBBase.getContentUri(), values, TransferTable.COLUMN_ID + "=" + id, null);
 }