Disable mass APNG animation on low-memory devices.

This commit is contained in:
Greyson Parrelli
2021-01-24 16:37:32 -05:00
parent acbc17c909
commit 92b586c061
12 changed files with 125 additions and 30 deletions

View File

@@ -0,0 +1,30 @@
package org.thoughtcrime.securesms.util;
import android.app.ActivityManager;
import android.content.Context;
import androidx.annotation.NonNull;
/**
* Easy access to various properties of the device, typically to make performance-related decisions.
*/
public final class DeviceProperties {
/**
* Whether or not we believe the device has the performance capabilities to efficiently render
* large numbers of APNGs simultaneously.
*/
public static boolean shouldAllowApngStickerAnimation(@NonNull Context context) {
return !isLowMemoryDevice(context) && getMemoryClass(context) >= FeatureFlags.animatedStickerMinimumMemory();
}
public static boolean isLowMemoryDevice(@NonNull Context context) {
ActivityManager activityManager = ServiceUtil.getActivityManager(context);
return activityManager.isLowRamDevice();
}
public static int getMemoryClass(@NonNull Context context) {
ActivityManager activityManager = ServiceUtil.getActivityManager(context);
return activityManager.getMemoryClass();
}
}

View File

@@ -72,6 +72,7 @@ public final class FeatureFlags {
private static final String DEFAULT_MAX_BACKOFF = "android.defaultMaxBackoff";
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";
/**
* We will only store remote values for flags in this set. If you want a flag to be controllable
@@ -100,7 +101,8 @@ public final class FeatureFlags {
AUTOMATIC_SESSION_INTERVAL,
DEFAULT_MAX_BACKOFF,
OKHTTP_AUTOMATIC_RETRY,
SHARE_SELECTION_LIMIT
SHARE_SELECTION_LIMIT,
ANIMATED_STICKER_MIN_MEMORY
);
@VisibleForTesting
@@ -139,7 +141,8 @@ public final class FeatureFlags {
AUTOMATIC_SESSION_INTERVAL,
DEFAULT_MAX_BACKOFF,
OKHTTP_AUTOMATIC_RETRY,
SHARE_SELECTION_LIMIT
SHARE_SELECTION_LIMIT,
ANIMATED_STICKER_MIN_MEMORY
);
/**
@@ -324,6 +327,11 @@ 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() {
return getInteger(ANIMATED_STICKER_MIN_MEMORY, 193);
}
/** Only for rendering debug info. */
public static synchronized @NonNull Map<String, Object> getMemoryValues() {
return new TreeMap<>(REMOTE_VALUES);