Пример #1
0
 public static RetrieveConf parseRetrieveConf(byte[] data, int subId) {
   if (data != null) {
     final GenericPdu pdu =
         new PduParser(data, MmsConfig.get(subId).getSupportMmsContentDisposition()).parse();
     if (pdu != null) {
       if (pdu instanceof RetrieveConf) {
         return (RetrieveConf) pdu;
       } else {
         LogUtil.e(TAG, "MmsSender: downloaded pdu not RetrieveConf: " + pdu.getClass().getName());
       }
     } else {
       LogUtil.e(TAG, "MmsSender: downloaded pdu could not be parsed (invalid)");
     }
   }
   LogUtil.e(TAG, "MmsSender: downloaded pdu is empty");
   return null;
 }
Пример #2
0
 public static SendConf parseSendConf(byte[] response, int subId) {
   if (response != null) {
     final GenericPdu respPdu =
         new PduParser(response, MmsConfig.get(subId).getSupportMmsContentDisposition()).parse();
     if (respPdu != null) {
       if (respPdu instanceof SendConf) {
         return (SendConf) respPdu;
       } else {
         LogUtil.e(TAG, "MmsSender: send response not SendConf");
       }
     } else {
       // Invalid PDU
       LogUtil.e(TAG, "MmsSender: send invalid response");
     }
   }
   // Empty or invalid response
   return null;
 }
Пример #3
0
 private static Uri writePduToTempFile(final Context context, final GenericPdu pdu, int subId)
     throws MmsFailureException {
   final Uri contentUri = MmsFileProvider.buildRawMmsUri();
   final File tempFile = MmsFileProvider.getFile(contentUri);
   FileOutputStream writer = null;
   try {
     // Ensure rawmms directory exists
     tempFile.getParentFile().mkdirs();
     writer = new FileOutputStream(tempFile);
     final byte[] pduBytes = new PduComposer(context, pdu).make();
     if (pduBytes == null) {
       throw new MmsFailureException(MmsUtils.MMS_REQUEST_NO_RETRY, "Failed to compose PDU");
     }
     if (pduBytes.length > MmsConfig.get(subId).getMaxMessageSize()) {
       throw new MmsFailureException(
           MmsUtils.MMS_REQUEST_NO_RETRY, MessageData.RAW_TELEPHONY_STATUS_MESSAGE_TOO_BIG);
     }
     writer.write(pduBytes);
   } catch (final IOException e) {
     if (tempFile != null) {
       tempFile.delete();
     }
     LogUtil.e(TAG, "Cannot create temporary file " + tempFile.getAbsolutePath(), e);
     throw new MmsFailureException(MmsUtils.MMS_REQUEST_AUTO_RETRY, "Cannot create raw mms file");
   } catch (final OutOfMemoryError e) {
     if (tempFile != null) {
       tempFile.delete();
     }
     LogUtil.e(TAG, "Out of memory in composing PDU", e);
     throw new MmsFailureException(
         MmsUtils.MMS_REQUEST_MANUAL_RETRY, MessageData.RAW_TELEPHONY_STATUS_MESSAGE_TOO_BIG);
   } finally {
     if (writer != null) {
       try {
         writer.close();
       } catch (final IOException e) {
         // no action we can take here
       }
     }
   }
   return contentUri;
 }
Пример #4
0
 /**
  * Send NotifyRespInd (response to mms auto download).
  *
  * @param context Context
  * @param subId subscription to use to send the response
  * @param transactionId The transaction id of the MMS message
  * @param contentLocation The url of the MMS message
  * @param status The status to send with the NotifyRespInd
  * @throws MmsFailureException
  * @throws InvalidHeaderValueException
  */
 public static void sendNotifyResponseForMmsDownload(
     final Context context,
     final int subId,
     final byte[] transactionId,
     final String contentLocation,
     final int status)
     throws MmsFailureException, InvalidHeaderValueException {
   // Create the M-NotifyResp.ind
   final NotifyRespInd notifyRespInd =
       new NotifyRespInd(PduHeaders.CURRENT_MMS_VERSION, transactionId, status);
   final Uri messageUri = Uri.parse(contentLocation);
   // Pack M-NotifyResp.ind and send it
   sendMms(
       context,
       subId,
       messageUri,
       MmsConfig.get(subId).getNotifyWapMMSC() ? contentLocation : null,
       notifyRespInd,
       false /* responseImportant */,
       null /* sentIntentExtras */);
 }
Пример #5
0
 /**
  * Send AcknowledgeInd (response to mms manual download). Ignore failures.
  *
  * @param context Context
  * @param subId The SIM's subId we are currently using
  * @param transactionId The transaction id of the MMS message
  * @param contentLocation The url of the MMS message
  * @throws MmsFailureException
  * @throws InvalidHeaderValueException
  */
 public static void sendAcknowledgeForMmsDownload(
     final Context context,
     final int subId,
     final byte[] transactionId,
     final String contentLocation)
     throws MmsFailureException, InvalidHeaderValueException {
   final String selfNumber = PhoneUtils.get(subId).getCanonicalForSelf(true /*allowOverride*/);
   // Create the M-Acknowledge.ind
   final AcknowledgeInd acknowledgeInd =
       new AcknowledgeInd(PduHeaders.CURRENT_MMS_VERSION, transactionId);
   acknowledgeInd.setFrom(new EncodedStringValue(selfNumber));
   final Uri messageUri = Uri.parse(contentLocation);
   // Sending
   sendMms(
       context,
       subId,
       messageUri,
       MmsConfig.get(subId).getNotifyWapMMSC() ? contentLocation : null,
       acknowledgeInd,
       false /*responseImportant*/,
       null /* sentIntentExtras */);
 }