-
-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable mass APNG animation on low-memory devices.
- Loading branch information
1 parent
acbc17c
commit 92b586c
Showing
12 changed files
with
125 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
app/src/main/java/org/thoughtcrime/securesms/glide/cache/ApngOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.thoughtcrime.securesms.glide.cache; | ||
|
||
import com.bumptech.glide.load.Option; | ||
|
||
import org.signal.core.util.Conversions; | ||
|
||
/** | ||
* Holds options that can be used to alter how APNGs are decoded in Glide. | ||
*/ | ||
public final class ApngOptions { | ||
|
||
private static final String KEY = "org.signal.skip_apng"; | ||
|
||
public static Option<Boolean> ANIMATE = Option.disk(KEY, true, (keyBytes, value, messageDigest) -> { | ||
messageDigest.update(keyBytes); | ||
messageDigest.update(Conversions.intToByteArray(value ? 1 : 0)); | ||
}); | ||
|
||
private ApngOptions() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
app/src/main/java/org/thoughtcrime/securesms/util/DeviceProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
Oops, something went wrong.