session-android/src/org/thoughtcrime/securesms/mms/MmsConfigManager.java
Moxie Marlinspike 51d6144591 Significant MMS changes
1) Remove all our PDU code and switch to the PDU code from the
   klinker library

2) Switch to using the system Lollipop MMS library by default,
   and falling back to our own custom library if that fails.

3) Format SMIL differently, using code from klinker instead of
   what we've pieced together.

4) Pull per-carrier MMS media constraints from the XML config
   files in the klinker library, instead of hardcoding it at 280kb.

Hopefully this is an improvement, but given that MMS is involved,
it will probably make things worse instead.
2017-05-08 18:14:55 -07:00

54 lines
1.7 KiB
Java

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