Ejemplo n.º 1
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;
 }