mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
remove unused classes
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
public class ApnUnavailableException extends Exception {
|
||||
|
||||
public ApnUnavailableException() {
|
||||
}
|
||||
|
||||
public ApnUnavailableException(String detailMessage) {
|
||||
super(detailMessage);
|
||||
}
|
||||
|
||||
public ApnUnavailableException(Throwable throwable) {
|
||||
super(throwable);
|
||||
}
|
||||
|
||||
public ApnUnavailableException(String detailMessage, Throwable throwable) {
|
||||
super(detailMessage, throwable);
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.Build.VERSION;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import android.provider.ContactsContract;
|
||||
|
||||
import com.bumptech.glide.load.data.StreamLocalUriFetcher;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
|
||||
class ContactPhotoLocalUriFetcher extends StreamLocalUriFetcher {
|
||||
|
||||
private static final String TAG = ContactPhotoLocalUriFetcher.class.getSimpleName();
|
||||
|
||||
ContactPhotoLocalUriFetcher(Context context, Uri uri) {
|
||||
super(context.getContentResolver(), uri);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InputStream loadResource(Uri uri, ContentResolver contentResolver)
|
||||
throws FileNotFoundException
|
||||
{
|
||||
if (VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH) {
|
||||
return ContactsContract.Contacts.openContactPhotoInputStream(contentResolver, uri, true);
|
||||
} else {
|
||||
return ContactsContract.Contacts.openContactPhotoInputStream(contentResolver, uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build.VERSION;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.telephony.SmsManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.android.mms.InvalidHeaderValueException;
|
||||
import com.google.android.mms.pdu_alt.NotifyRespInd;
|
||||
import com.google.android.mms.pdu_alt.PduComposer;
|
||||
import com.google.android.mms.pdu_alt.PduHeaders;
|
||||
import com.google.android.mms.pdu_alt.PduParser;
|
||||
import com.google.android.mms.pdu_alt.RetrieveConf;
|
||||
|
||||
import org.thoughtcrime.securesms.providers.MmsBodyProvider;
|
||||
import org.thoughtcrime.securesms.transport.UndeliverableMessageException;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
public class IncomingLollipopMmsConnection extends LollipopMmsConnection implements IncomingMmsConnection {
|
||||
|
||||
public static final String ACTION = IncomingLollipopMmsConnection.class.getCanonicalName() + "MMS_DOWNLOADED_ACTION";
|
||||
private static final String TAG = IncomingLollipopMmsConnection.class.getSimpleName();
|
||||
|
||||
public IncomingLollipopMmsConnection(Context context) {
|
||||
super(context, ACTION);
|
||||
}
|
||||
|
||||
@TargetApi(VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
public synchronized void onResult(Context context, Intent intent) {
|
||||
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP_MR1) {
|
||||
Log.w(TAG, "HTTP status: " + intent.getIntExtra(SmsManager.EXTRA_MMS_HTTP_STATUS, -1));
|
||||
}
|
||||
Log.w(TAG, "code: " + getResultCode() + ", result string: " + getResultData());
|
||||
}
|
||||
|
||||
@Override
|
||||
@TargetApi(VERSION_CODES.LOLLIPOP)
|
||||
public synchronized @Nullable RetrieveConf retrieve(@NonNull String contentLocation,
|
||||
byte[] transactionId,
|
||||
int subscriptionId) throws MmsException
|
||||
{
|
||||
beginTransaction();
|
||||
|
||||
try {
|
||||
MmsBodyProvider.Pointer pointer = MmsBodyProvider.makeTemporaryPointer(getContext());
|
||||
|
||||
Log.w(TAG, "downloading multimedia from " + contentLocation + " to " + pointer.getUri());
|
||||
|
||||
SmsManager smsManager;
|
||||
|
||||
if (VERSION.SDK_INT >= 22 && subscriptionId != -1) {
|
||||
smsManager = SmsManager.getSmsManagerForSubscriptionId(subscriptionId);
|
||||
} else {
|
||||
smsManager = SmsManager.getDefault();
|
||||
}
|
||||
|
||||
smsManager.downloadMultimediaMessage(getContext(),
|
||||
contentLocation,
|
||||
pointer.getUri(),
|
||||
null,
|
||||
getPendingIntent());
|
||||
|
||||
waitForResult();
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
Util.copy(pointer.getInputStream(), baos);
|
||||
pointer.close();
|
||||
|
||||
Log.w(TAG, baos.size() + "-byte response: ");// + Hex.dump(baos.toByteArray()));
|
||||
|
||||
RetrieveConf retrieved = (RetrieveConf) new PduParser(baos.toByteArray()).parse();
|
||||
|
||||
if (retrieved == null) return null;
|
||||
|
||||
sendRetrievedAcknowledgement(transactionId, retrieved.getMmsVersion(), subscriptionId);
|
||||
return retrieved;
|
||||
} catch (IOException | TimeoutException e) {
|
||||
Log.w(TAG, e);
|
||||
throw new MmsException(e);
|
||||
} finally {
|
||||
endTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
private void sendRetrievedAcknowledgement(byte[] transactionId, int mmsVersion, int subscriptionId) {
|
||||
try {
|
||||
NotifyRespInd retrieveResponse = new NotifyRespInd(mmsVersion, transactionId, PduHeaders.STATUS_RETRIEVED);
|
||||
new OutgoingLollipopMmsConnection(getContext()).send(new PduComposer(getContext(), retrieveResponse).make(), subscriptionId);
|
||||
} catch (UndeliverableMessageException e) {
|
||||
Log.w(TAG, e);
|
||||
} catch (InvalidHeaderValueException e) {
|
||||
Log.w(TAG, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.google.android.mms.pdu_alt.RetrieveConf;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface IncomingMmsConnection {
|
||||
@Nullable
|
||||
RetrieveConf retrieve(@NonNull String contentLocation, byte[] transactionId, int subscriptionId) throws MmsException, MmsRadioException, ApnUnavailableException, IOException;
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.util.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
public abstract class LollipopMmsConnection extends BroadcastReceiver {
|
||||
private static final String TAG = LollipopMmsConnection.class.getSimpleName();
|
||||
|
||||
private final Context context;
|
||||
private final String action;
|
||||
|
||||
private boolean resultAvailable;
|
||||
|
||||
public abstract void onResult(Context context, Intent intent);
|
||||
|
||||
protected LollipopMmsConnection(Context context, String action) {
|
||||
super();
|
||||
this.context = context;
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void onReceive(Context context, Intent intent) {
|
||||
Log.w(TAG, "onReceive()");
|
||||
if (!action.equals(intent.getAction())) {
|
||||
Log.w(TAG, "received broadcast with unexpected action " + intent.getAction());
|
||||
return;
|
||||
}
|
||||
|
||||
onResult(context, intent);
|
||||
|
||||
resultAvailable = true;
|
||||
notifyAll();
|
||||
}
|
||||
|
||||
protected void beginTransaction() {
|
||||
getContext().getApplicationContext().registerReceiver(this, new IntentFilter(action));
|
||||
}
|
||||
|
||||
protected void endTransaction() {
|
||||
getContext().getApplicationContext().unregisterReceiver(this);
|
||||
resultAvailable = false;
|
||||
}
|
||||
|
||||
protected void waitForResult() throws TimeoutException {
|
||||
long timeoutExpiration = System.currentTimeMillis() + 60000;
|
||||
while (!resultAvailable) {
|
||||
Util.wait(this, Math.max(1, timeoutExpiration - System.currentTimeMillis()));
|
||||
if (System.currentTimeMillis() >= timeoutExpiration) {
|
||||
throw new TimeoutException("timeout when waiting for MMS");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected PendingIntent getPendingIntent() {
|
||||
return PendingIntent.getBroadcast(getContext(), 1, new Intent(action), PendingIntent.FLAG_ONE_SHOT);
|
||||
}
|
||||
|
||||
protected Context getContext() {
|
||||
return context;
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2014 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
public class MediaNotFoundException extends Exception {
|
||||
|
||||
public MediaNotFoundException() {
|
||||
}
|
||||
|
||||
public MediaNotFoundException(String detailMessage) {
|
||||
super(detailMessage);
|
||||
}
|
||||
|
||||
public MediaNotFoundException(Throwable throwable) {
|
||||
super(throwable);
|
||||
}
|
||||
|
||||
public MediaNotFoundException(String detailMessage, Throwable throwable) {
|
||||
super(detailMessage, throwable);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2011 Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
public class MediaTooLargeException extends Exception {
|
||||
|
||||
public MediaTooLargeException() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public MediaTooLargeException(String detailMessage) {
|
||||
super(detailMessage);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public MediaTooLargeException(Throwable throwable) {
|
||||
super(throwable);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public MediaTooLargeException(String detailMessage, Throwable throwable) {
|
||||
super(detailMessage, throwable);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.WorkerThread;
|
||||
|
||||
import com.android.mms.service_alt.MmsConfig;
|
||||
|
||||
import org.thoughtcrime.securesms.util.dualsim.SubscriptionInfoCompat;
|
||||
import org.thoughtcrime.securesms.util.dualsim.SubscriptionManagerCompat;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MmsConfigManager {
|
||||
|
||||
private static Map<Integer, MmsConfig> mmsConfigMap = new HashMap<>();
|
||||
|
||||
@WorkerThread
|
||||
public synchronized static @Nullable MmsConfig getMmsConfig(Context context, int subscriptionId) {
|
||||
if (mmsConfigMap.containsKey(subscriptionId)) {
|
||||
return mmsConfigMap.get(subscriptionId);
|
||||
}
|
||||
|
||||
MmsConfig loadedConfig = loadMmsConfig(context, subscriptionId);
|
||||
|
||||
if (loadedConfig != null) mmsConfigMap.put(subscriptionId, loadedConfig);
|
||||
|
||||
return loadedConfig;
|
||||
}
|
||||
|
||||
private static MmsConfig loadMmsConfig(Context context, int subscriptionId) {
|
||||
if (subscriptionId != -1 && Build.VERSION.SDK_INT >= 24) {
|
||||
Optional<SubscriptionInfoCompat> subscriptionInfo = new SubscriptionManagerCompat(context).getActiveSubscriptionInfo(subscriptionId);
|
||||
|
||||
if (subscriptionInfo.isPresent()) {
|
||||
Configuration configuration = context.getResources().getConfiguration();
|
||||
configuration.mcc = subscriptionInfo.get().getMcc();
|
||||
configuration.mnc = subscriptionInfo.get().getMnc();
|
||||
|
||||
Context subcontext = context.createConfigurationContext(configuration);
|
||||
return new MmsConfig(subcontext, subscriptionId);
|
||||
}
|
||||
}
|
||||
|
||||
return new MmsConfig(context, subscriptionId);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,24 +18,24 @@ class MmsMediaConstraints extends MediaConstraints {
|
||||
|
||||
@Override
|
||||
public int getImageMaxWidth(Context context) {
|
||||
MmsConfig mmsConfig = MmsConfigManager.getMmsConfig(context, subscriptionId);
|
||||
|
||||
if (mmsConfig != null) {
|
||||
MmsConfig.Overridden overridden = new MmsConfig.Overridden(mmsConfig, new Bundle());
|
||||
return overridden.getMaxImageWidth();
|
||||
}
|
||||
// MmsConfig mmsConfig = MmsConfigManager.getMmsConfig(context, subscriptionId);
|
||||
//
|
||||
// if (mmsConfig != null) {
|
||||
// MmsConfig.Overridden overridden = new MmsConfig.Overridden(mmsConfig, new Bundle());
|
||||
// return overridden.getMaxImageWidth();
|
||||
// }
|
||||
|
||||
return DEFAULT_MAX_IMAGE_DIMEN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getImageMaxHeight(Context context) {
|
||||
MmsConfig mmsConfig = MmsConfigManager.getMmsConfig(context, subscriptionId);
|
||||
|
||||
if (mmsConfig != null) {
|
||||
MmsConfig.Overridden overridden = new MmsConfig.Overridden(mmsConfig, new Bundle());
|
||||
return overridden.getMaxImageHeight();
|
||||
}
|
||||
// MmsConfig mmsConfig = MmsConfigManager.getMmsConfig(context, subscriptionId);
|
||||
//
|
||||
// if (mmsConfig != null) {
|
||||
// MmsConfig.Overridden overridden = new MmsConfig.Overridden(mmsConfig, new Bundle());
|
||||
// return overridden.getMaxImageHeight();
|
||||
// }
|
||||
|
||||
return DEFAULT_MAX_IMAGE_DIMEN;
|
||||
}
|
||||
@@ -66,12 +66,12 @@ class MmsMediaConstraints extends MediaConstraints {
|
||||
}
|
||||
|
||||
private int getMaxMessageSize(Context context) {
|
||||
MmsConfig mmsConfig = MmsConfigManager.getMmsConfig(context, subscriptionId);
|
||||
|
||||
if (mmsConfig != null) {
|
||||
MmsConfig.Overridden overridden = new MmsConfig.Overridden(mmsConfig, new Bundle());
|
||||
return overridden.getMaxMessageSize();
|
||||
}
|
||||
// MmsConfig mmsConfig = MmsConfigManager.getMmsConfig(context, subscriptionId);
|
||||
//
|
||||
// if (mmsConfig != null) {
|
||||
// MmsConfig.Overridden overridden = new MmsConfig.Overridden(mmsConfig, new Bundle());
|
||||
// return overridden.getMaxMessageSize();
|
||||
// }
|
||||
|
||||
return DEFAULT_MAX_MESSAGE_SIZE;
|
||||
}
|
||||
|
||||
@@ -1,165 +0,0 @@
|
||||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.PowerManager;
|
||||
import android.util.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class MmsRadio {
|
||||
|
||||
private static final String TAG = MmsRadio.class.getSimpleName();
|
||||
|
||||
private static MmsRadio instance;
|
||||
|
||||
public static synchronized MmsRadio getInstance(Context context) {
|
||||
if (instance == null)
|
||||
instance = new MmsRadio(context.getApplicationContext());
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
///
|
||||
|
||||
private static final String FEATURE_ENABLE_MMS = "enableMMS";
|
||||
private static final int APN_ALREADY_ACTIVE = 0;
|
||||
public static final int TYPE_MOBILE_MMS = 2;
|
||||
|
||||
private final Context context;
|
||||
|
||||
private ConnectivityManager connectivityManager;
|
||||
private ConnectivityListener connectivityListener;
|
||||
private PowerManager.WakeLock wakeLock;
|
||||
private int connectedCounter = 0;
|
||||
|
||||
private MmsRadio(Context context) {
|
||||
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
this.context = context;
|
||||
this.connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
this.wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MMS Connection");
|
||||
this.wakeLock.setReferenceCounted(true);
|
||||
}
|
||||
|
||||
public synchronized void disconnect() {
|
||||
Log.w("MmsRadio", "MMS Radio Disconnect Called...");
|
||||
wakeLock.release();
|
||||
connectedCounter--;
|
||||
|
||||
Log.w("MmsRadio", "Reference count: " + connectedCounter);
|
||||
|
||||
if (connectedCounter == 0) {
|
||||
Log.w("MmsRadio", "Turning off MMS radio...");
|
||||
try {
|
||||
final Method stopUsingNetworkFeatureMethod = connectivityManager.getClass().getMethod("stopUsingNetworkFeature", Integer.TYPE, String.class);
|
||||
stopUsingNetworkFeatureMethod.invoke(connectivityManager, ConnectivityManager.TYPE_MOBILE, FEATURE_ENABLE_MMS);
|
||||
} catch (NoSuchMethodException nsme) {
|
||||
Log.w(TAG, nsme);
|
||||
} catch (IllegalAccessException iae) {
|
||||
Log.w(TAG, iae);
|
||||
} catch (InvocationTargetException ite) {
|
||||
Log.w(TAG, ite);
|
||||
}
|
||||
|
||||
if (connectivityListener != null) {
|
||||
Log.w("MmsRadio", "Unregistering receiver...");
|
||||
context.unregisterReceiver(connectivityListener);
|
||||
connectivityListener = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void connect() throws MmsRadioException {
|
||||
int status;
|
||||
|
||||
try {
|
||||
final Method startUsingNetworkFeatureMethod = connectivityManager.getClass().getMethod("startUsingNetworkFeature", Integer.TYPE, String.class);
|
||||
status = (int)startUsingNetworkFeatureMethod.invoke(connectivityManager, ConnectivityManager.TYPE_MOBILE, FEATURE_ENABLE_MMS);
|
||||
} catch (NoSuchMethodException nsme) {
|
||||
throw new MmsRadioException(nsme);
|
||||
} catch (IllegalAccessException iae) {
|
||||
throw new MmsRadioException(iae);
|
||||
} catch (InvocationTargetException ite) {
|
||||
throw new MmsRadioException(ite);
|
||||
}
|
||||
|
||||
Log.w("MmsRadio", "startUsingNetworkFeature status: " + status);
|
||||
|
||||
if (status == APN_ALREADY_ACTIVE) {
|
||||
wakeLock.acquire();
|
||||
connectedCounter++;
|
||||
return;
|
||||
} else {
|
||||
wakeLock.acquire();
|
||||
connectedCounter++;
|
||||
|
||||
if (connectivityListener == null) {
|
||||
IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
|
||||
connectivityListener = new ConnectivityListener();
|
||||
context.registerReceiver(connectivityListener, filter);
|
||||
}
|
||||
|
||||
Util.wait(this, 30000);
|
||||
|
||||
if (!isConnected()) {
|
||||
Log.w("MmsRadio", "Got back from connectivity wait, and not connected...");
|
||||
disconnect();
|
||||
throw new MmsRadioException("Unable to successfully enable MMS radio.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isConnected() {
|
||||
NetworkInfo info = connectivityManager.getNetworkInfo(TYPE_MOBILE_MMS);
|
||||
|
||||
Log.w("MmsRadio", "Connected: " + info);
|
||||
|
||||
if ((info == null) || (info.getType() != TYPE_MOBILE_MMS) || !info.isConnected())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isConnectivityPossible() {
|
||||
NetworkInfo networkInfo = connectivityManager.getNetworkInfo(TYPE_MOBILE_MMS);
|
||||
|
||||
return networkInfo != null && networkInfo.isAvailable();
|
||||
}
|
||||
|
||||
private boolean isConnectivityFailure() {
|
||||
NetworkInfo networkInfo = connectivityManager.getNetworkInfo(TYPE_MOBILE_MMS);
|
||||
|
||||
return networkInfo == null || networkInfo.getDetailedState() == NetworkInfo.DetailedState.FAILED;
|
||||
}
|
||||
|
||||
private synchronized void issueConnectivityChange() {
|
||||
if (isConnected()) {
|
||||
Log.w("MmsRadio", "Notifying connected...");
|
||||
notifyAll();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isConnected() && (isConnectivityFailure() || !isConnectivityPossible())) {
|
||||
Log.w("MmsRadio", "Notifying not connected...");
|
||||
notifyAll();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private class ConnectivityListener extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Log.w("MmsRadio", "Got connectivity change...");
|
||||
issueConnectivityChange();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
public class MmsRadioException extends Throwable {
|
||||
public MmsRadioException(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
public MmsRadioException(Exception e) {
|
||||
super(e);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
public class MmsSendResult {
|
||||
|
||||
private final byte[] messageId;
|
||||
private final int responseStatus;
|
||||
|
||||
public MmsSendResult(byte[] messageId, int responseStatus) {
|
||||
this.messageId = messageId;
|
||||
this.responseStatus = responseStatus;
|
||||
}
|
||||
|
||||
public int getResponseStatus() {
|
||||
return responseStatus;
|
||||
}
|
||||
|
||||
public byte[] getMessageId() {
|
||||
return messageId;
|
||||
}
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build.VERSION;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.telephony.SmsManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.mms.service_alt.MmsConfig;
|
||||
import com.google.android.mms.pdu_alt.PduParser;
|
||||
import com.google.android.mms.pdu_alt.SendConf;
|
||||
|
||||
import org.thoughtcrime.securesms.providers.MmsBodyProvider;
|
||||
import org.thoughtcrime.securesms.transport.UndeliverableMessageException;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
public class OutgoingLollipopMmsConnection extends LollipopMmsConnection implements OutgoingMmsConnection {
|
||||
private static final String TAG = OutgoingLollipopMmsConnection.class.getSimpleName();
|
||||
private static final String ACTION = OutgoingLollipopMmsConnection.class.getCanonicalName() + "MMS_SENT_ACTION";
|
||||
|
||||
private byte[] response;
|
||||
|
||||
public OutgoingLollipopMmsConnection(Context context) {
|
||||
super(context, ACTION);
|
||||
}
|
||||
|
||||
@TargetApi(VERSION_CODES.LOLLIPOP_MR1)
|
||||
@Override
|
||||
public synchronized void onResult(Context context, Intent intent) {
|
||||
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP_MR1) {
|
||||
Log.w(TAG, "HTTP status: " + intent.getIntExtra(SmsManager.EXTRA_MMS_HTTP_STATUS, -1));
|
||||
}
|
||||
|
||||
response = intent.getByteArrayExtra(SmsManager.EXTRA_MMS_DATA);
|
||||
}
|
||||
|
||||
@Override
|
||||
@TargetApi(VERSION_CODES.LOLLIPOP)
|
||||
public @Nullable synchronized SendConf send(@NonNull byte[] pduBytes, int subscriptionId)
|
||||
throws UndeliverableMessageException
|
||||
{
|
||||
beginTransaction();
|
||||
try {
|
||||
MmsBodyProvider.Pointer pointer = MmsBodyProvider.makeTemporaryPointer(getContext());
|
||||
Util.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.w(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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.google.android.mms.pdu_alt.SendConf;
|
||||
|
||||
import org.thoughtcrime.securesms.transport.UndeliverableMessageException;
|
||||
|
||||
|
||||
public interface OutgoingMmsConnection {
|
||||
@Nullable
|
||||
SendConf send(@NonNull byte[] pduBytes, int subscriptionId) throws UndeliverableMessageException;
|
||||
}
|
||||
Reference in New Issue
Block a user