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);
}
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();
}
}
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();
}
}
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);
}
}
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;
}
}
Aggregations