mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-29 03:07:47 +00:00
ab82ff0b69
1) Utilize the hidden API requestRouteToHostAddress that takes an InetAddress (IPv6-capable) instead of a forced IPv4 integer- encoded address. Will fallback to the IPv4 one if reflection fails for whatever reason. 2) If on Lollipop and our manual MMS code doesn't work, will try to use the Lollipop API and give it 60 seconds instead of 30, since I did run into the timeout not being long enough in certain conditions and I'm thinking maybe it just wasn't long enough for some carriers. Closes #3105 // FREEBIE
67 lines
2.3 KiB
Java
67 lines
2.3 KiB
Java
package org.thoughtcrime.securesms.mms;
|
|
|
|
import android.content.Context;
|
|
import android.net.ConnectivityManager;
|
|
import android.net.NetworkInfo;
|
|
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 java.net.Inet6Address;
|
|
import java.net.InterfaceAddress;
|
|
import java.net.NetworkInterface;
|
|
import java.net.SocketException;
|
|
import java.util.Enumeration;
|
|
|
|
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;
|
|
}
|
|
|
|
@Nullable @Override public SendConf send(@NonNull byte[] pduBytes)
|
|
throws UndeliverableMessageException
|
|
{
|
|
try {
|
|
Log.w(TAG, "Sending via legacy connection");
|
|
return new OutgoingLegacyMmsConnection(context).send(pduBytes);
|
|
} catch (UndeliverableMessageException | ApnUnavailableException e) {
|
|
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
|
|
Log.w(TAG, "Falling back to try sending via Lollipop API");
|
|
return new OutgoingLollipopMmsConnection(context).send(pduBytes);
|
|
} else {
|
|
throw new UndeliverableMessageException(e);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Nullable @Override public RetrieveConf retrieve(@NonNull String contentLocation,
|
|
byte[] transactionId)
|
|
throws MmsException, MmsRadioException, ApnUnavailableException, IOException
|
|
{
|
|
try {
|
|
Log.w(TAG, "Receiving via legacy connection");
|
|
return new IncomingLegacyMmsConnection(context).retrieve(contentLocation, transactionId);
|
|
} catch (MmsRadioException | IOException | ApnUnavailableException e) {
|
|
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);
|
|
} else {
|
|
throw e;
|
|
}
|
|
}
|
|
}
|
|
}
|