Improve logging around APNG animation disabling.

This commit is contained in:
Greyson Parrelli
2024-03-18 09:00:15 -04:00
committed by Cody Henthorne
parent 7a69df42a7
commit 450dc2f368
2 changed files with 23 additions and 8 deletions

View File

@@ -9,27 +9,41 @@ import android.os.Build;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import org.signal.core.util.logging.Log;
/**
* Easy access to various properties of the device, typically to make performance-related decisions.
*/
public final class DeviceProperties {
private static final String TAG = Log.tag(DeviceProperties.class);
/**
* 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) {
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());
if (isLowMemoryDevice(context)) {
return false;
}
if (memoryMb < FeatureFlags.animatedStickerMinimumTotalMemoryMb()) {
return false;
}
if (getMemoryClass(context) < FeatureFlags.animatedStickerMinimumMemoryClass()) {
return false;
}
if (memoryInfo.lowMemory) {
Log.w(TAG, "Currently in a low-memory situation! Can't render APNG.");
return false;
}
return true;
}
public static boolean isLowMemoryDevice(@NonNull Context context) {