From 8857b7e0c1a908c1853742b05d7aca7c63880dc9 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 19 Nov 2023 15:10:26 -0500 Subject: [PATCH] Use custom threshold for what's consider a low RAM device --- app/src/main/java/eu/kanade/tachiyomi/App.kt | 5 ++--- .../kanade/tachiyomi/util/system/DeviceUtil.kt | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/App.kt b/app/src/main/java/eu/kanade/tachiyomi/App.kt index 6c293a635..67ed7146e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/App.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/App.kt @@ -1,7 +1,6 @@ package eu.kanade.tachiyomi import android.annotation.SuppressLint -import android.app.ActivityManager import android.app.Application import android.app.PendingIntent import android.content.BroadcastReceiver @@ -12,7 +11,6 @@ import android.os.Build import android.os.Looper import android.webkit.WebView import androidx.core.content.ContextCompat -import androidx.core.content.getSystemService import androidx.lifecycle.DefaultLifecycleObserver import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.ProcessLifecycleOwner @@ -39,6 +37,7 @@ import eu.kanade.tachiyomi.di.PreferenceModule import eu.kanade.tachiyomi.network.NetworkHelper import eu.kanade.tachiyomi.network.NetworkPreferences import eu.kanade.tachiyomi.ui.base.delegate.SecureActivityDelegate +import eu.kanade.tachiyomi.util.system.DeviceUtil import eu.kanade.tachiyomi.util.system.WebViewUtil import eu.kanade.tachiyomi.util.system.animatorDurationScale import eu.kanade.tachiyomi.util.system.cancelNotification @@ -157,7 +156,7 @@ class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory { callFactory(callFactoryInit) diskCache(diskCacheInit) crossfade((300 * this@App.animatorDurationScale).toInt()) - allowRgb565(getSystemService()!!.isLowRamDevice) + allowRgb565(DeviceUtil.isLowRamDevice(this@App)) if (networkPreferences.verboseLogging().get()) logger(DebugLogger()) // Coil spawns a new thread for every image load by default diff --git a/core/src/main/java/eu/kanade/tachiyomi/util/system/DeviceUtil.kt b/core/src/main/java/eu/kanade/tachiyomi/util/system/DeviceUtil.kt index 9e0177129..e2011f0c5 100644 --- a/core/src/main/java/eu/kanade/tachiyomi/util/system/DeviceUtil.kt +++ b/core/src/main/java/eu/kanade/tachiyomi/util/system/DeviceUtil.kt @@ -1,7 +1,10 @@ package eu.kanade.tachiyomi.util.system import android.annotation.SuppressLint +import android.app.ActivityManager +import android.content.Context import android.os.Build +import androidx.core.content.getSystemService import logcat.LogPriority import tachiyomi.core.util.system.logcat @@ -65,6 +68,20 @@ object DeviceUtil { "com.zui.resolver", ) + /** + * ActivityManager#isLowRamDevice is based on a system property, which isn't + * necessarily trustworthy. 1GB is supposedly the regular threshold. + * + * Instead, we consider anything with less than 3GB of RAM as low memory + * considering how heavy image processing can be. + */ + fun isLowRamDevice(context: Context): Boolean { + val memInfo = ActivityManager.MemoryInfo() + context.getSystemService()!!.getMemoryInfo(memInfo) + val totalMemBytes = memInfo.totalMem + return totalMemBytes < 3L * 1024 * 1024 * 1024 + } + @SuppressLint("PrivateApi") private fun getSystemProperty(key: String?): String? { return try {