diff options
author | Zephyron <zephyron@citron-emu.org> | 2025-01-17 19:59:13 +1000 |
---|---|---|
committer | Zephyron <zephyron@citron-emu.org> | 2025-01-17 19:59:13 +1000 |
commit | 369847897796e40cdb9eb9a467965bbdb48c7def (patch) | |
tree | bebc53c9f1905985871533de3bd42e15a73a7731 /src/android/app | |
parent | 382999025af8a95aa791fd00c24f24ecd54596d4 (diff) |
android: Fix battery temperature reading in EmulationFragment
Replaces the battery temperature reading implementation with a more
compatible approach using ACTION_BATTERY_CHANGED broadcast intent.
This change provides better backwards compatibility and adds proper
error handling for the temperature reading functionality.
Diffstat (limited to 'src/android/app')
-rw-r--r-- | src/android/app/build.gradle.kts | 2 | ||||
-rw-r--r-- | src/android/app/src/main/java/org/citron/citron_emu/fragments/EmulationFragment.kt | 17 |
2 files changed, 13 insertions, 6 deletions
diff --git a/src/android/app/build.gradle.kts b/src/android/app/build.gradle.kts index 62299c538..3e5665c2f 100644 --- a/src/android/app/build.gradle.kts +++ b/src/android/app/build.gradle.kts @@ -28,7 +28,7 @@ android { namespace = "org.citron.citron_emu" compileSdkVersion = "android-34" - ndkVersion = "26.1.10909125" // "27.2.12479018" // "28.0.12433566 rc1"// "28.0.12674087 rc2" // "26.1.10909125" + ndkVersion = "27.2.12479018" // "27.2.12479018" // "28.0.12433566 rc1"// "28.0.12674087 rc2" // "26.1.10909125" buildFeatures { viewBinding = true diff --git a/src/android/app/src/main/java/org/citron/citron_emu/fragments/EmulationFragment.kt b/src/android/app/src/main/java/org/citron/citron_emu/fragments/EmulationFragment.kt index d39d25898..93a15def9 100644 --- a/src/android/app/src/main/java/org/citron/citron_emu/fragments/EmulationFragment.kt +++ b/src/android/app/src/main/java/org/citron/citron_emu/fragments/EmulationFragment.kt @@ -7,6 +7,8 @@ import android.annotation.SuppressLint import android.app.AlertDialog import android.content.Context import android.content.DialogInterface +import android.content.Intent +import android.content.IntentFilter import android.content.pm.ActivityInfo import android.content.res.Configuration import android.net.Uri @@ -1094,10 +1096,15 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { } private fun getBatteryTemperature(context: Context): Float { - val batteryManager = context.getSystemService(Context.BATTERY_SERVICE) as BatteryManager - // Get temperature in tenths of a degree Celsius - val temperature = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_TEMPERATURE) - // Convert to degrees Celsius - return temperature / 10.0f + try { + val batteryIntent = context.registerReceiver(null, IntentFilter(Intent.ACTION_BATTERY_CHANGED)) + // Temperature in tenths of a degree Celsius + val temperature = batteryIntent?.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0) ?: 0 + // Convert to degrees Celsius + return temperature / 10.0f + } catch (e: Exception) { + Log.error("[EmulationFragment] Failed to get battery temperature: ${e.message}") + return 0.0f + } } } |