kopia lustrzana https://github.com/ryukoposting/Signal-Android
Update logic on deciding whether to bulk animate stickers.
rodzic
17fb815805
commit
073034dd3c
|
@ -17,6 +17,7 @@ import org.thoughtcrime.securesms.BuildConfig;
|
|||
import org.thoughtcrime.securesms.util.AppSignatureUtil;
|
||||
import org.thoughtcrime.securesms.util.ByteUnit;
|
||||
import org.thoughtcrime.securesms.util.CensorshipUtil;
|
||||
import org.thoughtcrime.securesms.util.DeviceProperties;
|
||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
@ -54,6 +55,7 @@ public class LogSectionSystemInfo implements LogSection {
|
|||
builder.append("ABIs : ").append(TextUtils.join(", ", getSupportedAbis())).append("\n");
|
||||
builder.append("Memory : ").append(getMemoryUsage()).append("\n");
|
||||
builder.append("Memclass : ").append(getMemoryClass(context)).append("\n");
|
||||
builder.append("MemInfo : ").append(getMemoryInfo(context)).append("\n");
|
||||
builder.append("OS Host : ").append(Build.HOST).append("\n");
|
||||
builder.append("Censored : ").append(CensorshipUtil.isCensored(context)).append("\n");
|
||||
builder.append("Play Services : ").append(getPlayServicesString(context)).append("\n");
|
||||
|
@ -102,6 +104,12 @@ public class LogSectionSystemInfo implements LogSection {
|
|||
return activityManager.getMemoryClass() + lowMem;
|
||||
}
|
||||
|
||||
private static @NonNull String getMemoryInfo(Context context) {
|
||||
ActivityManager.MemoryInfo info = DeviceProperties.getMemoryInfo(context);
|
||||
return String.format(Locale.US, "availMem: %d mb, totalMem: %d mb, threshold: %d mb, lowMemory: %b",
|
||||
ByteUnit.BYTES.toMegabytes(info.availMem), ByteUnit.BYTES.toMegabytes(info.totalMem), ByteUnit.BYTES.toMegabytes(info.threshold), info.lowMemory);
|
||||
}
|
||||
|
||||
private static @NonNull Iterable<String> getSupportedAbis() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
return Arrays.asList(Build.SUPPORTED_ABIS);
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityManager.MemoryInfo;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
|
@ -15,7 +17,17 @@ public final class DeviceProperties {
|
|||
* large numbers of APNGs simultaneously.
|
||||
*/
|
||||
public static boolean shouldAllowApngStickerAnimation(@NonNull Context context) {
|
||||
return !isLowMemoryDevice(context) && getMemoryClass(context) >= FeatureFlags.animatedStickerMinimumMemory();
|
||||
if (Build.VERSION.SDK_INT < 26) {
|
||||
return false;
|
||||
}
|
||||
|
||||
MemoryInfo memoryInfo = getMemoryInfo(context);
|
||||
int memoryMb = (int) ByteUnit.BYTES.toMegabytes(memoryInfo.totalMem);
|
||||
|
||||
return !isLowMemoryDevice(context) &&
|
||||
!memoryInfo.lowMemory &&
|
||||
(memoryMb >= FeatureFlags.animatedStickerMinimumTotalMemoryMb() ||
|
||||
getMemoryClass(context) >= FeatureFlags.animatedStickerMinimumMemoryClass());
|
||||
}
|
||||
|
||||
public static boolean isLowMemoryDevice(@NonNull Context context) {
|
||||
|
@ -27,4 +39,13 @@ public final class DeviceProperties {
|
|||
ActivityManager activityManager = ServiceUtil.getActivityManager(context);
|
||||
return activityManager.getMemoryClass();
|
||||
}
|
||||
|
||||
public static @NonNull MemoryInfo getMemoryInfo(@NonNull Context context) {
|
||||
MemoryInfo info = new MemoryInfo();
|
||||
ActivityManager activityManager = ServiceUtil.getActivityManager(context);
|
||||
|
||||
activityManager.getMemoryInfo(info);
|
||||
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,6 +73,7 @@ public final class FeatureFlags {
|
|||
private static final String OKHTTP_AUTOMATIC_RETRY = "android.okhttpAutomaticRetry";
|
||||
private static final String SHARE_SELECTION_LIMIT = "android.share.limit";
|
||||
private static final String ANIMATED_STICKER_MIN_MEMORY = "android.animatedStickerMinMemory";
|
||||
private static final String ANIMATED_STICKER_MIN_TOTAL_MEMORY = "android.animatedStickerMinTotalMemory";
|
||||
|
||||
/**
|
||||
* We will only store remote values for flags in this set. If you want a flag to be controllable
|
||||
|
@ -102,7 +103,8 @@ public final class FeatureFlags {
|
|||
DEFAULT_MAX_BACKOFF,
|
||||
OKHTTP_AUTOMATIC_RETRY,
|
||||
SHARE_SELECTION_LIMIT,
|
||||
ANIMATED_STICKER_MIN_MEMORY
|
||||
ANIMATED_STICKER_MIN_MEMORY,
|
||||
ANIMATED_STICKER_MIN_TOTAL_MEMORY
|
||||
);
|
||||
|
||||
@VisibleForTesting
|
||||
|
@ -142,7 +144,8 @@ public final class FeatureFlags {
|
|||
DEFAULT_MAX_BACKOFF,
|
||||
OKHTTP_AUTOMATIC_RETRY,
|
||||
SHARE_SELECTION_LIMIT,
|
||||
ANIMATED_STICKER_MIN_MEMORY
|
||||
ANIMATED_STICKER_MIN_MEMORY,
|
||||
ANIMATED_STICKER_MIN_TOTAL_MEMORY
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -327,11 +330,16 @@ public final class FeatureFlags {
|
|||
return getBoolean(OKHTTP_AUTOMATIC_RETRY, false);
|
||||
}
|
||||
|
||||
/** The minimum amount of memory required for rendering animated stickers in the keyboard and such */
|
||||
public static int animatedStickerMinimumMemory() {
|
||||
/** The minimum memory class required for rendering animated stickers in the keyboard and such */
|
||||
public static int animatedStickerMinimumMemoryClass() {
|
||||
return getInteger(ANIMATED_STICKER_MIN_MEMORY, 193);
|
||||
}
|
||||
|
||||
/** The minimum total memory for rendering animated stickers in the keyboard and such */
|
||||
public static int animatedStickerMinimumTotalMemoryMb() {
|
||||
return getInteger(ANIMATED_STICKER_MIN_TOTAL_MEMORY, (int) ByteUnit.GIGABYTES.toMegabytes(3));
|
||||
}
|
||||
|
||||
/** Only for rendering debug info. */
|
||||
public static synchronized @NonNull Map<String, Object> getMemoryValues() {
|
||||
return new TreeMap<>(REMOTE_VALUES);
|
||||
|
|
Ładowanie…
Reference in New Issue