summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Abandoned Cart2023-06-16 13:26:24 -0400
committerGravatar Abandoned Cart2023-06-21 18:24:49 -0400
commit699e78c666188a06ef218a54e0d85023f3fa93fc (patch)
treee883485569caa93defb38b22182b716c1c0853b7
parentMerge pull request #10864 from t895/disable-mali-driver (diff)
downloadyuzu-699e78c666188a06ef218a54e0d85023f3fa93fc.tar.gz
yuzu-699e78c666188a06ef218a54e0d85023f3fa93fc.tar.xz
yuzu-699e78c666188a06ef218a54e0d85023f3fa93fc.zip
android: Add a notice when RAM inadequate
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt17
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/MemoryUtil.kt58
-rw-r--r--src/android/app/src/main/res/values/strings.xml1
3 files changed, 75 insertions, 1 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt
index f0a6753a9..75d994c9c 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt
@@ -27,13 +27,13 @@ import android.view.MotionEvent
27import android.view.Surface 27import android.view.Surface
28import android.view.View 28import android.view.View
29import android.view.inputmethod.InputMethodManager 29import android.view.inputmethod.InputMethodManager
30import android.widget.Toast
30import androidx.activity.viewModels 31import androidx.activity.viewModels
31import androidx.appcompat.app.AppCompatActivity 32import androidx.appcompat.app.AppCompatActivity
32import androidx.core.view.WindowCompat 33import androidx.core.view.WindowCompat
33import androidx.core.view.WindowInsetsCompat 34import androidx.core.view.WindowInsetsCompat
34import androidx.core.view.WindowInsetsControllerCompat 35import androidx.core.view.WindowInsetsControllerCompat
35import androidx.navigation.fragment.NavHostFragment 36import androidx.navigation.fragment.NavHostFragment
36import kotlin.math.roundToInt
37import org.yuzu.yuzu_emu.NativeLibrary 37import org.yuzu.yuzu_emu.NativeLibrary
38import org.yuzu.yuzu_emu.R 38import org.yuzu.yuzu_emu.R
39import org.yuzu.yuzu_emu.databinding.ActivityEmulationBinding 39import org.yuzu.yuzu_emu.databinding.ActivityEmulationBinding
@@ -44,8 +44,10 @@ import org.yuzu.yuzu_emu.model.Game
44import org.yuzu.yuzu_emu.utils.ControllerMappingHelper 44import org.yuzu.yuzu_emu.utils.ControllerMappingHelper
45import org.yuzu.yuzu_emu.utils.ForegroundService 45import org.yuzu.yuzu_emu.utils.ForegroundService
46import org.yuzu.yuzu_emu.utils.InputHandler 46import org.yuzu.yuzu_emu.utils.InputHandler
47import org.yuzu.yuzu_emu.utils.MemoryUtil
47import org.yuzu.yuzu_emu.utils.NfcReader 48import org.yuzu.yuzu_emu.utils.NfcReader
48import org.yuzu.yuzu_emu.utils.ThemeHelper 49import org.yuzu.yuzu_emu.utils.ThemeHelper
50import kotlin.math.roundToInt
49 51
50class EmulationActivity : AppCompatActivity(), SensorEventListener { 52class EmulationActivity : AppCompatActivity(), SensorEventListener {
51 private lateinit var binding: ActivityEmulationBinding 53 private lateinit var binding: ActivityEmulationBinding
@@ -102,6 +104,19 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener {
102 inputHandler = InputHandler() 104 inputHandler = InputHandler()
103 inputHandler.initialize() 105 inputHandler.initialize()
104 106
107 val memoryUtil = MemoryUtil(this)
108 if (memoryUtil.isLessThan(8, MemoryUtil.Gb)) {
109 Toast.makeText(
110 this,
111 getString(
112 R.string.device_memory_inadequate_description,
113 memoryUtil.getDeviceRAM(),
114 "8 GB"
115 ),
116 Toast.LENGTH_LONG
117 ).show()
118 }
119
105 // Start a foreground service to prevent the app from getting killed in the background 120 // Start a foreground service to prevent the app from getting killed in the background
106 val startIntent = Intent(this, ForegroundService::class.java) 121 val startIntent = Intent(this, ForegroundService::class.java)
107 startForegroundService(startIntent) 122 startForegroundService(startIntent)
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/MemoryUtil.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/MemoryUtil.kt
new file mode 100644
index 000000000..390767e47
--- /dev/null
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/MemoryUtil.kt
@@ -0,0 +1,58 @@
1// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4package org.yuzu.yuzu_emu.utils
5
6import android.app.ActivityManager
7import android.content.Context
8import java.util.Locale
9
10class MemoryUtil(context: Context) {
11
12 private val Long.floatForm: String
13 get() = String.format(Locale.ROOT, "%.2f", this.toDouble())
14
15 private fun bytesToSizeUnit(size: Long): String {
16 return when {
17 size < Kb -> size.floatForm + " byte"
18 size < Mb -> (size / Kb).floatForm + " KB"
19 size < Gb -> (size / Mb).floatForm + " MB"
20 size < Tb -> (size / Gb).floatForm + " GB"
21 size < Pb -> (size / Tb).floatForm + " TB"
22 size < Eb -> (size / Pb).floatForm + " Pb"
23 else -> (size / Eb).floatForm + " Eb"
24 }
25 }
26
27 private val totalMemory =
28 with(context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager) {
29 val memInfo = ActivityManager.MemoryInfo()
30 getMemoryInfo(memInfo)
31 memInfo.totalMem
32 }
33
34 fun isLessThan(minimum: Int, size: Long): Boolean {
35 return when (size) {
36 Kb -> totalMemory < Mb && totalMemory < minimum
37 Mb -> totalMemory < Gb && (totalMemory / Mb) < minimum
38 Gb -> totalMemory < Tb && (totalMemory / Gb) < minimum
39 Tb -> totalMemory < Pb && (totalMemory / Tb) < minimum
40 Pb -> totalMemory < Eb && (totalMemory / Pb) < minimum
41 Eb -> totalMemory / Eb < minimum
42 else -> totalMemory < Kb && totalMemory < minimum
43 }
44 }
45
46 fun getDeviceRAM(): String {
47 return bytesToSizeUnit(totalMemory)
48 }
49
50 companion object {
51 const val Kb: Long = 1024
52 const val Mb = Kb * 1024
53 const val Gb = Mb * 1024
54 const val Tb = Gb * 1024
55 const val Pb = Tb * 1024
56 const val Eb = Pb * 1024
57 }
58}
diff --git a/src/android/app/src/main/res/values/strings.xml b/src/android/app/src/main/res/values/strings.xml
index cc1d8c39d..7d37d2bee 100644
--- a/src/android/app/src/main/res/values/strings.xml
+++ b/src/android/app/src/main/res/values/strings.xml
@@ -270,6 +270,7 @@
270 <string name="fatal_error">Fatal Error</string> 270 <string name="fatal_error">Fatal Error</string>
271 <string name="fatal_error_message">A fatal error occurred. Check the log for details.\nContinuing emulation may result in crashes and bugs.</string> 271 <string name="fatal_error_message">A fatal error occurred. Check the log for details.\nContinuing emulation may result in crashes and bugs.</string>
272 <string name="performance_warning">Turning off this setting will significantly reduce emulation performance! For the best experience, it is recommended that you leave this setting enabled.</string> 272 <string name="performance_warning">Turning off this setting will significantly reduce emulation performance! For the best experience, it is recommended that you leave this setting enabled.</string>
273 <string name="device_memory_inadequate_description">Device RAM: %1$s\nRecommended: %2$s</string>
273 274
274 <!-- Region Names --> 275 <!-- Region Names -->
275 <string name="region_japan">Japan</string> 276 <string name="region_japan">Japan</string>