Search in sources :

Example 1 with MmsConfig

use of com.android.mms.service_alt.MmsConfig in project Signal-Android by signalapp.

the class MmsConfigManager method loadMmsConfig.

@NonNull
private static MmsConfig loadMmsConfig(Context context, int subscriptionId) {
    Optional<SubscriptionInfoCompat> subscriptionInfo = new SubscriptionManagerCompat(context).getActiveSubscriptionInfo(subscriptionId);
    if (subscriptionInfo.isPresent()) {
        SubscriptionInfoCompat subscriptionInfoCompat = subscriptionInfo.get();
        Configuration configuration = context.getResources().getConfiguration();
        configuration.mcc = subscriptionInfoCompat.getMcc();
        configuration.mnc = subscriptionInfoCompat.getMnc();
        Context subContext = context.createConfigurationContext(configuration);
        return new MmsConfig(subContext, subscriptionId);
    }
    return new MmsConfig(context, subscriptionId);
}
Also used : Context(android.content.Context) SubscriptionManagerCompat(org.thoughtcrime.securesms.util.dualsim.SubscriptionManagerCompat) MmsConfig(com.android.mms.service_alt.MmsConfig) Configuration(android.content.res.Configuration) SubscriptionInfoCompat(org.thoughtcrime.securesms.util.dualsim.SubscriptionInfoCompat) NonNull(androidx.annotation.NonNull)

Example 2 with MmsConfig

use of com.android.mms.service_alt.MmsConfig in project Signal-Android by signalapp.

the class OutgoingLollipopMmsConnection method send.

@Override
@TargetApi(VERSION_CODES.LOLLIPOP)
@Nullable
public synchronized SendConf send(@NonNull byte[] pduBytes, int subscriptionId) throws UndeliverableMessageException {
    beginTransaction();
    try {
        MmsBodyProvider.Pointer pointer = MmsBodyProvider.makeTemporaryPointer(getContext());
        StreamUtil.copy(new ByteArrayInputStream(pduBytes), pointer.getOutputStream());
        SmsManager smsManager;
        if (VERSION.SDK_INT >= 22 && subscriptionId != -1) {
            smsManager = SmsManager.getSmsManagerForSubscriptionId(subscriptionId);
        } else {
            smsManager = SmsManager.getDefault();
        }
        Bundle configOverrides = new Bundle();
        configOverrides.putBoolean(SmsManager.MMS_CONFIG_GROUP_MMS_ENABLED, true);
        MmsConfig mmsConfig = MmsConfigManager.getMmsConfig(getContext(), subscriptionId);
        if (mmsConfig != null) {
            MmsConfig.Overridden overridden = new MmsConfig.Overridden(mmsConfig, new Bundle());
            configOverrides.putString(SmsManager.MMS_CONFIG_HTTP_PARAMS, overridden.getHttpParams());
            configOverrides.putInt(SmsManager.MMS_CONFIG_MAX_MESSAGE_SIZE, overridden.getMaxMessageSize());
        }
        smsManager.sendMultimediaMessage(getContext(), pointer.getUri(), null, configOverrides, getPendingIntent());
        waitForResult();
        Log.i(TAG, "MMS broadcast received and processed.");
        pointer.close();
        if (response == null) {
            throw new UndeliverableMessageException("Null response.");
        }
        return (SendConf) new PduParser(response).parse();
    } catch (IOException | TimeoutException e) {
        throw new UndeliverableMessageException(e);
    } finally {
        endTransaction();
    }
}
Also used : MmsBodyProvider(org.thoughtcrime.securesms.providers.MmsBodyProvider) SendConf(com.google.android.mms.pdu_alt.SendConf) PduParser(com.google.android.mms.pdu_alt.PduParser) Bundle(android.os.Bundle) IOException(java.io.IOException) SmsManager(android.telephony.SmsManager) MmsConfig(com.android.mms.service_alt.MmsConfig) ByteArrayInputStream(java.io.ByteArrayInputStream) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException) TimeoutException(java.util.concurrent.TimeoutException) TargetApi(android.annotation.TargetApi) Nullable(androidx.annotation.Nullable)

Example 3 with MmsConfig

use of com.android.mms.service_alt.MmsConfig in project Signal-Android by WhisperSystems.

the class OutgoingLollipopMmsConnection method send.

@Override
@TargetApi(VERSION_CODES.LOLLIPOP)
@Nullable
public synchronized SendConf send(@NonNull byte[] pduBytes, int subscriptionId) throws UndeliverableMessageException {
    beginTransaction();
    try {
        MmsBodyProvider.Pointer pointer = MmsBodyProvider.makeTemporaryPointer(getContext());
        StreamUtil.copy(new ByteArrayInputStream(pduBytes), pointer.getOutputStream());
        SmsManager smsManager;
        if (VERSION.SDK_INT >= 22 && subscriptionId != -1) {
            smsManager = SmsManager.getSmsManagerForSubscriptionId(subscriptionId);
        } else {
            smsManager = SmsManager.getDefault();
        }
        Bundle configOverrides = new Bundle();
        configOverrides.putBoolean(SmsManager.MMS_CONFIG_GROUP_MMS_ENABLED, true);
        MmsConfig mmsConfig = MmsConfigManager.getMmsConfig(getContext(), subscriptionId);
        if (mmsConfig != null) {
            MmsConfig.Overridden overridden = new MmsConfig.Overridden(mmsConfig, new Bundle());
            configOverrides.putString(SmsManager.MMS_CONFIG_HTTP_PARAMS, overridden.getHttpParams());
            configOverrides.putInt(SmsManager.MMS_CONFIG_MAX_MESSAGE_SIZE, overridden.getMaxMessageSize());
        }
        smsManager.sendMultimediaMessage(getContext(), pointer.getUri(), null, configOverrides, getPendingIntent());
        waitForResult();
        Log.i(TAG, "MMS broadcast received and processed.");
        pointer.close();
        if (response == null) {
            throw new UndeliverableMessageException("Null response.");
        }
        return (SendConf) new PduParser(response).parse();
    } catch (IOException | TimeoutException e) {
        throw new UndeliverableMessageException(e);
    } finally {
        endTransaction();
    }
}
Also used : MmsBodyProvider(org.thoughtcrime.securesms.providers.MmsBodyProvider) SendConf(com.google.android.mms.pdu_alt.SendConf) PduParser(com.google.android.mms.pdu_alt.PduParser) Bundle(android.os.Bundle) IOException(java.io.IOException) SmsManager(android.telephony.SmsManager) MmsConfig(com.android.mms.service_alt.MmsConfig) ByteArrayInputStream(java.io.ByteArrayInputStream) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException) TimeoutException(java.util.concurrent.TimeoutException) TargetApi(android.annotation.TargetApi) Nullable(androidx.annotation.Nullable)

Example 4 with MmsConfig

use of com.android.mms.service_alt.MmsConfig in project qksms by moezbhatti.

the class MmsReceivedReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    Timber.v("MMS has finished downloading, persisting it to the database");
    String path = intent.getStringExtra(EXTRA_FILE_PATH);
    Timber.v(path);
    FileInputStream reader = null;
    Uri messageUri = null;
    String errorMessage = null;
    try {
        File mDownloadFile = new File(path);
        final int nBytes = (int) mDownloadFile.length();
        reader = new FileInputStream(mDownloadFile);
        final byte[] response = new byte[nBytes];
        reader.read(response, 0, nBytes);
        List<CommonAsyncTask> tasks = getNotificationTask(context, intent, response);
        messageUri = DownloadRequest.persist(context, response, new MmsConfig.Overridden(new MmsConfig(context), null), intent.getStringExtra(EXTRA_LOCATION_URL), Utils.getDefaultSubscriptionId(), null);
        Timber.v("response saved successfully");
        Timber.v("response length: " + response.length);
        mDownloadFile.delete();
        if (tasks != null) {
            Timber.v("running the common async notifier for download");
            for (CommonAsyncTask task : tasks) task.executeOnExecutor(RECEIVE_NOTIFICATION_EXECUTOR);
        }
    } catch (FileNotFoundException e) {
        errorMessage = "MMS received, file not found exception";
        Timber.e(e, errorMessage);
    } catch (IOException e) {
        errorMessage = "MMS received, io exception";
        Timber.e(e, errorMessage);
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException e) {
                errorMessage = "MMS received, io exception";
                Timber.e(e, "MMS received, io exception");
            }
        }
    }
    handleHttpError(context, intent);
    DownloadManager.finishDownload(intent.getStringExtra(EXTRA_LOCATION_URL));
    if (messageUri != null) {
        onMessageReceived(messageUri);
    }
    if (errorMessage != null) {
        onError(errorMessage);
    }
}
Also used : MmsConfig(com.android.mms.service_alt.MmsConfig) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Uri(android.net.Uri) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 5 with MmsConfig

use of com.android.mms.service_alt.MmsConfig in project qksms by moezbhatti.

the class MmsReceivedReceiver method getNotificationTask.

private List<CommonAsyncTask> getNotificationTask(Context context, Intent intent, byte[] response) {
    if (response.length == 0) {
        Timber.v("MmsReceivedReceiver.sendNotification blank response");
        return null;
    }
    if (getMmscInfoForReceptionAck() == null) {
        Timber.v("No MMSC information set, so no notification tasks will be able to complete");
        return null;
    }
    final GenericPdu pdu = (new PduParser(response, new MmsConfig.Overridden(new MmsConfig(context), null).getSupportMmsContentDisposition())).parse();
    if (pdu == null || !(pdu instanceof RetrieveConf)) {
        Timber.e("MmsReceivedReceiver.sendNotification failed to parse pdu");
        return null;
    }
    try {
        final NotificationInd ind = getNotificationInd(context, intent);
        final MmscInformation mmsc = getMmscInfoForReceptionAck();
        final TransactionSettings transactionSettings = new TransactionSettings(mmsc.mmscUrl, mmsc.mmsProxy, mmsc.proxyPort);
        final List<CommonAsyncTask> responseTasks = new ArrayList<>();
        responseTasks.add(new AcknowledgeIndTask(context, ind, transactionSettings, (RetrieveConf) pdu));
        responseTasks.add(new NotifyRespTask(context, ind, transactionSettings));
        return responseTasks;
    } catch (MmsException e) {
        Timber.e(e, "error");
        return null;
    }
}
Also used : PduParser(com.google.android.mms.pdu_alt.PduParser) NotificationInd(com.google.android.mms.pdu_alt.NotificationInd) ArrayList(java.util.ArrayList) MmsException(com.google.android.mms.MmsException) MmsConfig(com.android.mms.service_alt.MmsConfig) TransactionSettings(com.android.mms.transaction.TransactionSettings) GenericPdu(com.google.android.mms.pdu_alt.GenericPdu) RetrieveConf(com.google.android.mms.pdu_alt.RetrieveConf)

Aggregations

MmsConfig (com.android.mms.service_alt.MmsConfig)8 NonNull (androidx.annotation.NonNull)4 PduParser (com.google.android.mms.pdu_alt.PduParser)3 IOException (java.io.IOException)3 TargetApi (android.annotation.TargetApi)2 Context (android.content.Context)2 Configuration (android.content.res.Configuration)2 Bundle (android.os.Bundle)2 SmsManager (android.telephony.SmsManager)2 Nullable (androidx.annotation.Nullable)2 WorkerThread (androidx.annotation.WorkerThread)2 SendConf (com.google.android.mms.pdu_alt.SendConf)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 TimeoutException (java.util.concurrent.TimeoutException)2 MmsBodyProvider (org.thoughtcrime.securesms.providers.MmsBodyProvider)2 UndeliverableMessageException (org.thoughtcrime.securesms.transport.UndeliverableMessageException)2 SubscriptionInfoCompat (org.thoughtcrime.securesms.util.dualsim.SubscriptionInfoCompat)2 SubscriptionManagerCompat (org.thoughtcrime.securesms.util.dualsim.SubscriptionManagerCompat)2 Uri (android.net.Uri)1 TransactionSettings (com.android.mms.transaction.TransactionSettings)1