diff --git a/src/org/thoughtcrime/securesms/linkpreview/LinkPreviewRepository.java b/src/org/thoughtcrime/securesms/linkpreview/LinkPreviewRepository.java index 57273bced..dd9e11614 100644 --- a/src/org/thoughtcrime/securesms/linkpreview/LinkPreviewRepository.java +++ b/src/org/thoughtcrime/securesms/linkpreview/LinkPreviewRepository.java @@ -8,7 +8,6 @@ import android.text.Html; import android.text.TextUtils; import com.bumptech.glide.load.engine.DiskCacheStrategy; -import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; import com.bumptech.glide.request.FutureTarget; import org.thoughtcrime.securesms.attachments.Attachment; @@ -132,7 +131,7 @@ public class LinkPreviewRepository { .load(new ChunkedImageUrl(imageUrl)) .skipMemoryCache(true) .diskCacheStrategy(DiskCacheStrategy.NONE) - .downsample(DownsampleStrategy.AT_MOST) + .centerInside() .submit(1024, 1024); RequestController controller = () -> bitmapFuture.cancel(false); diff --git a/src/org/thoughtcrime/securesms/mms/MmsConfigManager.java b/src/org/thoughtcrime/securesms/mms/MmsConfigManager.java index 9f607e597..c0af33251 100644 --- a/src/org/thoughtcrime/securesms/mms/MmsConfigManager.java +++ b/src/org/thoughtcrime/securesms/mms/MmsConfigManager.java @@ -3,8 +3,7 @@ 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.NonNull; import android.support.annotation.WorkerThread; import com.android.mms.service_alt.MmsConfig; @@ -16,35 +15,35 @@ import org.whispersystems.libsignal.util.guava.Optional; import java.util.HashMap; import java.util.Map; -public class MmsConfigManager { +final class MmsConfigManager { - private static Map mmsConfigMap = new HashMap<>(); + private static final Map mmsConfigMap = new HashMap<>(); @WorkerThread - public synchronized static @Nullable MmsConfig getMmsConfig(Context context, int subscriptionId) { - if (mmsConfigMap.containsKey(subscriptionId)) { - return mmsConfigMap.get(subscriptionId); + synchronized static @NonNull MmsConfig getMmsConfig(Context context, int subscriptionId) { + MmsConfig mmsConfig = mmsConfigMap.get(subscriptionId); + if (mmsConfig != null) { + return mmsConfig; } MmsConfig loadedConfig = loadMmsConfig(context, subscriptionId); - if (loadedConfig != null) mmsConfigMap.put(subscriptionId, loadedConfig); + mmsConfigMap.put(subscriptionId, loadedConfig); return loadedConfig; } - private static MmsConfig loadMmsConfig(Context context, int subscriptionId) { - if (subscriptionId != -1 && Build.VERSION.SDK_INT >= 24) { - Optional subscriptionInfo = new SubscriptionManagerCompat(context).getActiveSubscriptionInfo(subscriptionId); + private static @NonNull MmsConfig loadMmsConfig(Context context, int subscriptionId) { + Optional subscriptionInfo = new SubscriptionManagerCompat(context).getActiveSubscriptionInfo(subscriptionId); - if (subscriptionInfo.isPresent()) { - Configuration configuration = context.getResources().getConfiguration(); - configuration.mcc = subscriptionInfo.get().getMcc(); - configuration.mnc = subscriptionInfo.get().getMnc(); + 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); - } + Context subContext = context.createConfigurationContext(configuration); + return new MmsConfig(subContext, subscriptionId); } return new MmsConfig(context, subscriptionId); diff --git a/src/org/thoughtcrime/securesms/mms/MmsMediaConstraints.java b/src/org/thoughtcrime/securesms/mms/MmsMediaConstraints.java index 4a9031390..d7b6c9666 100644 --- a/src/org/thoughtcrime/securesms/mms/MmsMediaConstraints.java +++ b/src/org/thoughtcrime/securesms/mms/MmsMediaConstraints.java @@ -1,43 +1,27 @@ package org.thoughtcrime.securesms.mms; import android.content.Context; -import android.os.Bundle; import com.android.mms.service_alt.MmsConfig; -class MmsMediaConstraints extends MediaConstraints { - - private static final int DEFAULT_MAX_IMAGE_DIMEN = 1024; - private static final int DEFAULT_MAX_MESSAGE_SIZE = 280 * 1024; +final class MmsMediaConstraints extends MediaConstraints { private final int subscriptionId; + private static final int MIN_IMAGE_DIMEN = 1024; + MmsMediaConstraints(int subscriptionId) { this.subscriptionId = subscriptionId; } @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(); - } - - return DEFAULT_MAX_IMAGE_DIMEN; + return Math.max(MIN_IMAGE_DIMEN, getOverriddenMmsConfig(context).getMaxImageWidth()); } @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(); - } - - return DEFAULT_MAX_IMAGE_DIMEN; + return Math.max(MIN_IMAGE_DIMEN, getOverriddenMmsConfig(context).getMaxImageHeight()); } @Override @@ -66,13 +50,12 @@ class MmsMediaConstraints extends MediaConstraints { } private int getMaxMessageSize(Context context) { + return getOverriddenMmsConfig(context).getMaxMessageSize(); + } + + private MmsConfig.Overridden getOverriddenMmsConfig(Context context) { 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; + return new MmsConfig.Overridden(mmsConfig, null); } } diff --git a/src/org/thoughtcrime/securesms/util/BitmapUtil.java b/src/org/thoughtcrime/securesms/util/BitmapUtil.java index 5f0b45012..c73ce7c8f 100644 --- a/src/org/thoughtcrime/securesms/util/BitmapUtil.java +++ b/src/org/thoughtcrime/securesms/util/BitmapUtil.java @@ -17,7 +17,6 @@ import org.thoughtcrime.securesms.logging.Log; import android.util.Pair; import com.bumptech.glide.load.engine.DiskCacheStrategy; -import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; import org.thoughtcrime.securesms.mms.GlideApp; import org.thoughtcrime.securesms.mms.MediaConstraints; @@ -68,7 +67,7 @@ public class BitmapUtil { .load(model) .skipMemoryCache(true) .diskCacheStrategy(DiskCacheStrategy.NONE) - .downsample(DownsampleStrategy.AT_MOST) + .centerInside() .submit(maxImageWidth, maxImageHeight) .get(); @@ -122,7 +121,7 @@ public class BitmapUtil { return GlideApp.with(context.getApplicationContext()) .asBitmap() .load(model) - .downsample(DownsampleStrategy.AT_MOST) + .centerInside() .submit(maxWidth, maxHeight) .get(); } catch (InterruptedException | ExecutionException e) {