mirror of
https://codeberg.org/yuzu-emu/yuzu.git
synced 2025-12-16 12:09:04 +00:00
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.
This commit is contained in:
parent
72e2f7130e
commit
3341368074
@ -7,6 +7,8 @@ import android.annotation.SuppressLint
|
|||||||
import android.app.AlertDialog
|
import android.app.AlertDialog
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.DialogInterface
|
import android.content.DialogInterface
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.IntentFilter
|
||||||
import android.content.pm.ActivityInfo
|
import android.content.pm.ActivityInfo
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
@ -1084,10 +1086,15 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getBatteryTemperature(context: Context): Float {
|
private fun getBatteryTemperature(context: Context): Float {
|
||||||
val batteryManager = context.getSystemService(Context.BATTERY_SERVICE) as BatteryManager
|
try {
|
||||||
// Get temperature in tenths of a degree Celsius
|
val batteryIntent = context.registerReceiver(null, IntentFilter(Intent.ACTION_BATTERY_CHANGED))
|
||||||
val temperature = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_TEMPERATURE)
|
// Temperature in tenths of a degree Celsius
|
||||||
// Convert to degrees Celsius
|
val temperature = batteryIntent?.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0) ?: 0
|
||||||
return temperature / 10.0f
|
// Convert to degrees Celsius
|
||||||
|
return temperature / 10.0f
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.error("[EmulationFragment] Failed to get battery temperature: ${e.message}")
|
||||||
|
return 0.0f
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user