feat: add device thermal state + extra getInfo telemetry - #359
feat: add device thermal state + extra getInfo telemetry#359dr-codswallop wants to merge 4 commits into
Conversation
Apps can throttle work from a normalized thermal bucket and event, and getInfo now reports processor counts, uptime, and total RAM so they can size work to the machine.
Align thermal state mapping by user-visible impact: Android `THERMAL_STATUS_LIGHT` now maps to `warm` alongside `MODERATE` instead of being treated as `normal`. Updated Kotlin/PHP docs to clarify the collapsed Android-to-shared mapping and why `SHUTDOWN` is grouped under `critical`.
Clarifies the NativePHP Mobile thermal-state documentation across iOS and Android. It explains the platform-specific mapping from raw values to Normal/Warm/Hot/Critical, notes Android 8-9 and simulator behavior, and aligns the docs in the PHP docs writer guidance, skill guide, and reference list.
|
Thanks for this Larry 🙏🏻 Nice feature, plenty of practical uses. Verified! buckets map correctly on both platforms, events fire on real changes only, cold start seeds without firing. What I ran into:
Android webviewThe monitor sends through
iOS webviewThe webview path delivers, and then the POST to The coercion you added to NativeComponent needs a twin there. Appearance survives this only because its constructor takes a string, which is why nobody hit it before. SimulatorThe simulator can be driven 🚀 If you want to speed up your testing: The Are you up to crossing those T's? Let me know or I'll have a look myself |
|
Correction on the Android half, hold off on that change for now. Kept digging and the same bypass hits That leaves the iOS 500 as the one thing on your side. I'll approve this to be merged after I fix #360 |
Updated `ThermalStateChanged` to accept either `ThermalState` enums or string values and normalize both constructor inputs to enums. This fixes event hydration when payloads come from webview/native JSON posts. Added unit and feature coverage to verify string payload handling, event dispatch hydration, and device thermal state updates via `_native/api/events`.
|
You're a wizard Larry. Thanks! This looks great. I'll give it another test once #360 is merged 🙌 |

Important note: currently untested on Android
Summary
Device::thermalState()plusThermalStateChangedso apps can throttle when the phone heats up (same query-plus-event pattern asSystem::appearance()).processorCount,activeProcessorCount,systemUptime, andmemTotalto the existingDevice::getInfo()JSON (alongside existingmemUsed). Thermal is not ongetInfo().php artisan native:install --force.Query
Off-device:
thermalState()isThermalState::Normal.getInfo()isnull. Android 8–9 still hasgetInfo(); only thermal is stubbed (normal, no event) — see Notes.JS:
device.thermalState()→{ state }. New keys are inside the existingdevice.getInfo()infostring.Event
Native\Mobile\Events\Device\ThermalStateChanged(BroadcastsGlobally). Payload:state+previous. Cold start does not fire it.Helpers:
isWarm(),isHot(),isCritical(),isWarmerThan(),isCoolerThan()on the enum;isWarming()/isCooling()on the event.Normalized thermal buckets
iOS
ProcessInfo.ThermalStatemaps 1:1. AndroidPowerManager(API 29+) collapses seven statuses onto the same four names. Unknown/null values are considerednormal.normal.nominalNONEwarm.fairLIGHT,MODERATEhot.seriousSEVEREcritical.criticalCRITICAL,EMERGENCY,SHUTDOWNBuckets follow user-visible impact, not constant names:
LIGHT/MODERATEare still fully usable (Warm),SEVEREis when UX is hit (Hot), and Android’s ownCRITICALmaps tocritical.SHUTDOWNfolds intocritical— iOS has no equivalent, and AOSP says apps often never receive that callback.Bonus tip: monitor thermal state changes in the background
ThermalStateChangeddoes not fire while the app is in the background. ProbeDevice::thermalState()from a scheduled command instead, compare it to the previous state, and notify if it has changed since last probed.Requires
nativephp/mobile-background-tasksandnativephp/mobile-local-notifications.Notes
PowerManager.getCurrentThermalStatus()andOnThermalStatusChangedListenerwere added in Android 10 (API 29). On 8–9,thermalState()is alwaysnormalandThermalStateChangednever fires.normal. Live events need a physical device. Android 10+ emulator:adb shell cmd thermalservice override-status <0-6>thenreset.