diff options
Diffstat (limited to 'src')
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 | |||
| 27 | import android.view.Surface | 27 | import android.view.Surface |
| 28 | import android.view.View | 28 | import android.view.View |
| 29 | import android.view.inputmethod.InputMethodManager | 29 | import android.view.inputmethod.InputMethodManager |
| 30 | import android.widget.Toast | ||
| 30 | import androidx.activity.viewModels | 31 | import androidx.activity.viewModels |
| 31 | import androidx.appcompat.app.AppCompatActivity | 32 | import androidx.appcompat.app.AppCompatActivity |
| 32 | import androidx.core.view.WindowCompat | 33 | import androidx.core.view.WindowCompat |
| 33 | import androidx.core.view.WindowInsetsCompat | 34 | import androidx.core.view.WindowInsetsCompat |
| 34 | import androidx.core.view.WindowInsetsControllerCompat | 35 | import androidx.core.view.WindowInsetsControllerCompat |
| 35 | import androidx.navigation.fragment.NavHostFragment | 36 | import androidx.navigation.fragment.NavHostFragment |
| 36 | import kotlin.math.roundToInt | ||
| 37 | import org.yuzu.yuzu_emu.NativeLibrary | 37 | import org.yuzu.yuzu_emu.NativeLibrary |
| 38 | import org.yuzu.yuzu_emu.R | 38 | import org.yuzu.yuzu_emu.R |
| 39 | import org.yuzu.yuzu_emu.databinding.ActivityEmulationBinding | 39 | import org.yuzu.yuzu_emu.databinding.ActivityEmulationBinding |
| @@ -44,8 +44,10 @@ import org.yuzu.yuzu_emu.model.Game | |||
| 44 | import org.yuzu.yuzu_emu.utils.ControllerMappingHelper | 44 | import org.yuzu.yuzu_emu.utils.ControllerMappingHelper |
| 45 | import org.yuzu.yuzu_emu.utils.ForegroundService | 45 | import org.yuzu.yuzu_emu.utils.ForegroundService |
| 46 | import org.yuzu.yuzu_emu.utils.InputHandler | 46 | import org.yuzu.yuzu_emu.utils.InputHandler |
| 47 | import org.yuzu.yuzu_emu.utils.MemoryUtil | ||
| 47 | import org.yuzu.yuzu_emu.utils.NfcReader | 48 | import org.yuzu.yuzu_emu.utils.NfcReader |
| 48 | import org.yuzu.yuzu_emu.utils.ThemeHelper | 49 | import org.yuzu.yuzu_emu.utils.ThemeHelper |
| 50 | import kotlin.math.roundToInt | ||
| 49 | 51 | ||
| 50 | class EmulationActivity : AppCompatActivity(), SensorEventListener { | 52 | class 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 | |||
| 4 | package org.yuzu.yuzu_emu.utils | ||
| 5 | |||
| 6 | import android.app.ActivityManager | ||
| 7 | import android.content.Context | ||
| 8 | import java.util.Locale | ||
| 9 | |||
| 10 | class 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> |