2015-05-01 19:03:05 +00:00
|
|
|
package org.thoughtcrime.securesms.mms;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2016-02-06 00:10:33 +00:00
|
|
|
import android.os.Build;
|
2015-05-01 19:03:05 +00:00
|
|
|
import android.os.Build.VERSION;
|
|
|
|
import android.os.Build.VERSION_CODES;
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.transport.UndeliverableMessageException;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import ws.com.google.android.mms.MmsException;
|
|
|
|
import ws.com.google.android.mms.pdu.RetrieveConf;
|
|
|
|
import ws.com.google.android.mms.pdu.SendConf;
|
|
|
|
|
|
|
|
public class CompatMmsConnection implements OutgoingMmsConnection, IncomingMmsConnection {
|
|
|
|
private static final String TAG = CompatMmsConnection.class.getSimpleName();
|
|
|
|
|
|
|
|
private Context context;
|
|
|
|
|
|
|
|
public CompatMmsConnection(Context context) {
|
|
|
|
this.context = context;
|
|
|
|
}
|
|
|
|
|
2015-10-13 01:25:05 +00:00
|
|
|
@Nullable
|
|
|
|
@Override
|
2016-02-06 00:10:33 +00:00
|
|
|
public SendConf send(@NonNull byte[] pduBytes, int subscriptionId)
|
2015-05-01 19:03:05 +00:00
|
|
|
throws UndeliverableMessageException
|
|
|
|
{
|
2016-02-06 00:10:33 +00:00
|
|
|
if (subscriptionId == -1 || VERSION.SDK_INT < 22) {
|
2015-05-01 19:03:05 +00:00
|
|
|
Log.w(TAG, "Sending via legacy connection");
|
2016-02-06 00:10:33 +00:00
|
|
|
try {
|
|
|
|
return new OutgoingLegacyMmsConnection(context).send(pduBytes, subscriptionId);
|
|
|
|
} catch (UndeliverableMessageException | ApnUnavailableException e) {
|
|
|
|
Log.w(TAG, e);
|
2015-05-01 19:03:05 +00:00
|
|
|
}
|
|
|
|
}
|
2016-02-06 00:10:33 +00:00
|
|
|
|
|
|
|
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
|
|
|
|
return new OutgoingLollipopMmsConnection(context).send(pduBytes, subscriptionId);
|
|
|
|
} else {
|
|
|
|
throw new UndeliverableMessageException("Lollipop API not available to try...");
|
|
|
|
}
|
2015-05-01 19:03:05 +00:00
|
|
|
}
|
|
|
|
|
2015-10-13 01:25:05 +00:00
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public RetrieveConf retrieve(@NonNull String contentLocation,
|
2016-02-06 00:10:33 +00:00
|
|
|
byte[] transactionId,
|
|
|
|
int subscriptionId)
|
2015-05-01 19:03:05 +00:00
|
|
|
throws MmsException, MmsRadioException, ApnUnavailableException, IOException
|
|
|
|
{
|
2016-02-06 00:10:33 +00:00
|
|
|
if (VERSION.SDK_INT < 22 || subscriptionId == -1) {
|
2015-05-01 19:03:05 +00:00
|
|
|
Log.w(TAG, "Receiving via legacy connection");
|
2016-02-06 00:10:33 +00:00
|
|
|
try {
|
|
|
|
return new IncomingLegacyMmsConnection(context).retrieve(contentLocation, transactionId, subscriptionId);
|
|
|
|
} catch (MmsRadioException | ApnUnavailableException | IOException e) {
|
|
|
|
Log.w(TAG, e);
|
2015-05-01 19:03:05 +00:00
|
|
|
}
|
|
|
|
}
|
2016-02-06 00:10:33 +00:00
|
|
|
|
|
|
|
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
|
|
|
|
Log.w(TAG, "Falling back to try receiving via Lollipop API");
|
|
|
|
return new IncomingLollipopMmsConnection(context).retrieve(contentLocation, transactionId, subscriptionId);
|
|
|
|
} else {
|
|
|
|
throw new IOException("Not able to use Lollipop APIs, giving up...");
|
|
|
|
}
|
2015-05-01 19:03:05 +00:00
|
|
|
}
|
|
|
|
}
|