MMS image quality.

Fixes #8590
- Scale image larger within the dimensions.
- Apply a minimum dimension of 1024.
This commit is contained in:
Alan Evans 2019-03-28 15:14:06 -03:00 committed by GitHub
parent e842f78457
commit ce6d2d9c69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 50 deletions

View File

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

View File

@ -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<Integer, MmsConfig> mmsConfigMap = new HashMap<>();
private static final 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);
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<SubscriptionInfoCompat> subscriptionInfo = new SubscriptionManagerCompat(context).getActiveSubscriptionInfo(subscriptionId);
private static @NonNull MmsConfig loadMmsConfig(Context context, int subscriptionId) {
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();
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);

View File

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

View File

@ -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) {