summaryrefslogtreecommitdiff
path: root/src/android
diff options
context:
space:
mode:
authorGravatar Charles Lombardo2023-11-03 15:51:17 -0400
committerGravatar Charles Lombardo2023-11-03 15:51:17 -0400
commit9bb8ac7cb6ac87fe5c0b82cd563ba62483761b4e (patch)
tree52aaa8bcf91f83ba6f0be8f23aa6ad3f31e715a6 /src/android
parentMerge pull request #11953 from t895/surface-tweak (diff)
downloadyuzu-9bb8ac7cb6ac87fe5c0b82cd563ba62483761b4e.tar.gz
yuzu-9bb8ac7cb6ac87fe5c0b82cd563ba62483761b4e.tar.xz
yuzu-9bb8ac7cb6ac87fe5c0b82cd563ba62483761b4e.zip
android: Fix fetching system memory size from MemoryUtil
We weren't rounding up the value at a unit before (GB, MB, etc) we were rounding up the total bytes and that would do nothing. This fixes that, and the check for total system memory during first emulation start where we tried to check the required system memory against 1 gigabyte.
Diffstat (limited to 'src/android')
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt2
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/MemoryUtil.kt34
2 files changed, 17 insertions, 19 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 da98d4ef5..054e4b755 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
@@ -107,7 +107,7 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener {
107 107
108 val preferences = PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext) 108 val preferences = PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext)
109 if (!preferences.getBoolean(Settings.PREF_MEMORY_WARNING_SHOWN, false)) { 109 if (!preferences.getBoolean(Settings.PREF_MEMORY_WARNING_SHOWN, false)) {
110 if (MemoryUtil.isLessThan(MemoryUtil.REQUIRED_MEMORY, MemoryUtil.Gb)) { 110 if (MemoryUtil.isLessThan(MemoryUtil.REQUIRED_MEMORY, MemoryUtil.totalMemory)) {
111 Toast.makeText( 111 Toast.makeText(
112 this, 112 this,
113 getString( 113 getString(
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 aa4a5539a..9076a86c4 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
@@ -27,7 +27,7 @@ object MemoryUtil {
27 const val Pb = Tb * 1024 27 const val Pb = Tb * 1024
28 const val Eb = Pb * 1024 28 const val Eb = Pb * 1024
29 29
30 private fun bytesToSizeUnit(size: Float): String = 30 private fun bytesToSizeUnit(size: Float, roundUp: Boolean = false): String =
31 when { 31 when {
32 size < Kb -> { 32 size < Kb -> {
33 context.getString( 33 context.getString(
@@ -39,63 +39,59 @@ object MemoryUtil {
39 size < Mb -> { 39 size < Mb -> {
40 context.getString( 40 context.getString(
41 R.string.memory_formatted, 41 R.string.memory_formatted,
42 (size / Kb).hundredths, 42 if (roundUp) ceil(size / Kb) else (size / Kb).hundredths,
43 context.getString(R.string.memory_kilobyte) 43 context.getString(R.string.memory_kilobyte)
44 ) 44 )
45 } 45 }
46 size < Gb -> { 46 size < Gb -> {
47 context.getString( 47 context.getString(
48 R.string.memory_formatted, 48 R.string.memory_formatted,
49 (size / Mb).hundredths, 49 if (roundUp) ceil(size / Mb) else (size / Mb).hundredths,
50 context.getString(R.string.memory_megabyte) 50 context.getString(R.string.memory_megabyte)
51 ) 51 )
52 } 52 }
53 size < Tb -> { 53 size < Tb -> {
54 context.getString( 54 context.getString(
55 R.string.memory_formatted, 55 R.string.memory_formatted,
56 (size / Gb).hundredths, 56 if (roundUp) ceil(size / Gb) else (size / Gb).hundredths,
57 context.getString(R.string.memory_gigabyte) 57 context.getString(R.string.memory_gigabyte)
58 ) 58 )
59 } 59 }
60 size < Pb -> { 60 size < Pb -> {
61 context.getString( 61 context.getString(
62 R.string.memory_formatted, 62 R.string.memory_formatted,
63 (size / Tb).hundredths, 63 if (roundUp) ceil(size / Tb) else (size / Tb).hundredths,
64 context.getString(R.string.memory_terabyte) 64 context.getString(R.string.memory_terabyte)
65 ) 65 )
66 } 66 }
67 size < Eb -> { 67 size < Eb -> {
68 context.getString( 68 context.getString(
69 R.string.memory_formatted, 69 R.string.memory_formatted,
70 (size / Pb).hundredths, 70 if (roundUp) ceil(size / Pb) else (size / Pb).hundredths,
71 context.getString(R.string.memory_petabyte) 71 context.getString(R.string.memory_petabyte)
72 ) 72 )
73 } 73 }
74 else -> { 74 else -> {
75 context.getString( 75 context.getString(
76 R.string.memory_formatted, 76 R.string.memory_formatted,
77 (size / Eb).hundredths, 77 if (roundUp) ceil(size / Eb) else (size / Eb).hundredths,
78 context.getString(R.string.memory_exabyte) 78 context.getString(R.string.memory_exabyte)
79 ) 79 )
80 } 80 }
81 } 81 }
82 82
83 // Devices are unlikely to have 0.5GB increments of memory so we'll just round up to account for 83 val totalMemory: Float
84 // the potential error created by memInfo.totalMem
85 private val totalMemory: Float
86 get() { 84 get() {
87 val memInfo = ActivityManager.MemoryInfo() 85 val memInfo = ActivityManager.MemoryInfo()
88 with(context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager) { 86 with(context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager) {
89 getMemoryInfo(memInfo) 87 getMemoryInfo(memInfo)
90 } 88 }
91 89
92 return ceil( 90 return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
93 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { 91 memInfo.advertisedMem.toFloat()
94 memInfo.advertisedMem.toFloat() 92 } else {
95 } else { 93 memInfo.totalMem.toFloat()
96 memInfo.totalMem.toFloat() 94 }
97 }
98 )
99 } 95 }
100 96
101 fun isLessThan(minimum: Int, size: Float): Boolean = 97 fun isLessThan(minimum: Int, size: Float): Boolean =
@@ -109,5 +105,7 @@ object MemoryUtil {
109 else -> totalMemory < Kb && totalMemory < minimum 105 else -> totalMemory < Kb && totalMemory < minimum
110 } 106 }
111 107
112 fun getDeviceRAM(): String = bytesToSizeUnit(totalMemory) 108 // Devices are unlikely to have 0.5GB increments of memory so we'll just round up to account for
109 // the potential error created by memInfo.totalMem
110 fun getDeviceRAM(): String = bytesToSizeUnit(totalMemory, true)
113} 111}