summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt9
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/MemoryUtil.kt100
-rw-r--r--src/android/app/src/main/res/values/strings.xml1
3 files changed, 85 insertions, 25 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 4052eead5..2c671fea3 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
@@ -47,6 +47,7 @@ import org.yuzu.yuzu_emu.utils.InputHandler
47import org.yuzu.yuzu_emu.utils.MemoryUtil 47import org.yuzu.yuzu_emu.utils.MemoryUtil
48import org.yuzu.yuzu_emu.utils.NfcReader 48import org.yuzu.yuzu_emu.utils.NfcReader
49import org.yuzu.yuzu_emu.utils.ThemeHelper 49import org.yuzu.yuzu_emu.utils.ThemeHelper
50import java.text.NumberFormat
50import kotlin.math.roundToInt 51import kotlin.math.roundToInt
51 52
52class EmulationActivity : AppCompatActivity(), SensorEventListener { 53class EmulationActivity : AppCompatActivity(), SensorEventListener {
@@ -106,13 +107,17 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener {
106 inputHandler = InputHandler() 107 inputHandler = InputHandler()
107 inputHandler.initialize() 108 inputHandler.initialize()
108 109
109 if (MemoryUtil.isLessThan(8, MemoryUtil.Gb)) { 110 if (MemoryUtil.isLessThan(MemoryUtil.REQUIRED_MEMORY, MemoryUtil.Gb)) {
110 Toast.makeText( 111 Toast.makeText(
111 this, 112 this,
112 getString( 113 getString(
113 R.string.device_memory_inadequate, 114 R.string.device_memory_inadequate,
114 MemoryUtil.getDeviceRAM(), 115 MemoryUtil.getDeviceRAM(),
115 "8 ${getString(R.string.memory_gigabyte)}" 116 getString(
117 R.string.memory_formatted,
118 NumberFormat.getInstance().format(MemoryUtil.REQUIRED_MEMORY),
119 getString(R.string.memory_gigabyte)
120 )
116 ), 121 ),
117 Toast.LENGTH_LONG 122 Toast.LENGTH_LONG
118 ).show() 123 ).show()
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
index 59e9f8f87..aa4a5539a 100644
--- 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
@@ -5,44 +5,101 @@ package org.yuzu.yuzu_emu.utils
5 5
6import android.app.ActivityManager 6import android.app.ActivityManager
7import android.content.Context 7import android.content.Context
8import android.os.Build
8import org.yuzu.yuzu_emu.R 9import org.yuzu.yuzu_emu.R
9import org.yuzu.yuzu_emu.YuzuApplication 10import org.yuzu.yuzu_emu.YuzuApplication
10import java.util.Locale 11import java.util.Locale
12import kotlin.math.ceil
11 13
12object MemoryUtil { 14object MemoryUtil {
13 private val context get() = YuzuApplication.appContext 15 private val context get() = YuzuApplication.appContext
14 16
15 private val Long.floatForm: String 17 private val Float.hundredths: String
16 get() = String.format(Locale.ROOT, "%.2f", this.toDouble()) 18 get() = String.format(Locale.ROOT, "%.2f", this)
17 19
18 const val Kb: Long = 1024 20 // Required total system memory
21 const val REQUIRED_MEMORY = 8
22
23 const val Kb: Float = 1024F
19 const val Mb = Kb * 1024 24 const val Mb = Kb * 1024
20 const val Gb = Mb * 1024 25 const val Gb = Mb * 1024
21 const val Tb = Gb * 1024 26 const val Tb = Gb * 1024
22 const val Pb = Tb * 1024 27 const val Pb = Tb * 1024
23 const val Eb = Pb * 1024 28 const val Eb = Pb * 1024
24 29
25 private fun bytesToSizeUnit(size: Long): String { 30 private fun bytesToSizeUnit(size: Float): String =
26 return when { 31 when {
27 size < Kb -> "${size.floatForm} ${context.getString(R.string.memory_byte)}" 32 size < Kb -> {
28 size < Mb -> "${(size / Kb).floatForm} ${context.getString(R.string.memory_kilobyte)}" 33 context.getString(
29 size < Gb -> "${(size / Mb).floatForm} ${context.getString(R.string.memory_megabyte)}" 34 R.string.memory_formatted,
30 size < Tb -> "${(size / Gb).floatForm} ${context.getString(R.string.memory_gigabyte)}" 35 size.hundredths,
31 size < Pb -> "${(size / Tb).floatForm} ${context.getString(R.string.memory_terabyte)}" 36 context.getString(R.string.memory_byte)
32 size < Eb -> "${(size / Pb).floatForm} ${context.getString(R.string.memory_petabyte)}" 37 )
33 else -> "${(size / Eb).floatForm} ${context.getString(R.string.memory_exabyte)}" 38 }
39 size < Mb -> {
40 context.getString(
41 R.string.memory_formatted,
42 (size / Kb).hundredths,
43 context.getString(R.string.memory_kilobyte)
44 )
45 }
46 size < Gb -> {
47 context.getString(
48 R.string.memory_formatted,
49 (size / Mb).hundredths,
50 context.getString(R.string.memory_megabyte)
51 )
52 }
53 size < Tb -> {
54 context.getString(
55 R.string.memory_formatted,
56 (size / Gb).hundredths,
57 context.getString(R.string.memory_gigabyte)
58 )
59 }
60 size < Pb -> {
61 context.getString(
62 R.string.memory_formatted,
63 (size / Tb).hundredths,
64 context.getString(R.string.memory_terabyte)
65 )
66 }
67 size < Eb -> {
68 context.getString(
69 R.string.memory_formatted,
70 (size / Pb).hundredths,
71 context.getString(R.string.memory_petabyte)
72 )
73 }
74 else -> {
75 context.getString(
76 R.string.memory_formatted,
77 (size / Eb).hundredths,
78 context.getString(R.string.memory_exabyte)
79 )
80 }
34 } 81 }
35 }
36 82
37 private val totalMemory = 83 // Devices are unlikely to have 0.5GB increments of memory so we'll just round up to account for
38 with(context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager) { 84 // the potential error created by memInfo.totalMem
85 private val totalMemory: Float
86 get() {
39 val memInfo = ActivityManager.MemoryInfo() 87 val memInfo = ActivityManager.MemoryInfo()
40 getMemoryInfo(memInfo) 88 with(context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager) {
41 memInfo.totalMem 89 getMemoryInfo(memInfo)
90 }
91
92 return ceil(
93 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
94 memInfo.advertisedMem.toFloat()
95 } else {
96 memInfo.totalMem.toFloat()
97 }
98 )
42 } 99 }
43 100
44 fun isLessThan(minimum: Int, size: Long): Boolean { 101 fun isLessThan(minimum: Int, size: Float): Boolean =
45 return when (size) { 102 when (size) {
46 Kb -> totalMemory < Mb && totalMemory < minimum 103 Kb -> totalMemory < Mb && totalMemory < minimum
47 Mb -> totalMemory < Gb && (totalMemory / Mb) < minimum 104 Mb -> totalMemory < Gb && (totalMemory / Mb) < minimum
48 Gb -> totalMemory < Tb && (totalMemory / Gb) < minimum 105 Gb -> totalMemory < Tb && (totalMemory / Gb) < minimum
@@ -51,9 +108,6 @@ object MemoryUtil {
51 Eb -> totalMemory / Eb < minimum 108 Eb -> totalMemory / Eb < minimum
52 else -> totalMemory < Kb && totalMemory < minimum 109 else -> totalMemory < Kb && totalMemory < minimum
53 } 110 }
54 }
55 111
56 fun getDeviceRAM(): String { 112 fun getDeviceRAM(): String = bytesToSizeUnit(totalMemory)
57 return bytesToSizeUnit(totalMemory)
58 }
59} 113}
diff --git a/src/android/app/src/main/res/values/strings.xml b/src/android/app/src/main/res/values/strings.xml
index af7450619..b3c737979 100644
--- a/src/android/app/src/main/res/values/strings.xml
+++ b/src/android/app/src/main/res/values/strings.xml
@@ -273,6 +273,7 @@
273 <string name="fatal_error_message">A fatal error occurred. Check the log for details.\nContinuing emulation may result in crashes and bugs.</string> 273 <string name="fatal_error_message">A fatal error occurred. Check the log for details.\nContinuing emulation may result in crashes and bugs.</string>
274 <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> 274 <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>
275 <string name="device_memory_inadequate">Device RAM: %1$s\nRecommended: %2$s</string> 275 <string name="device_memory_inadequate">Device RAM: %1$s\nRecommended: %2$s</string>
276 <string name="memory_formatted">%1$s %2$s</string>
276 277
277 <!-- Region Names --> 278 <!-- Region Names -->
278 <string name="region_japan">Japan</string> 279 <string name="region_japan">Japan</string>