1

Does anyone have a code snippet giving the CPU clock speed on an Android device?

Reason

I have written an Wear OS App using the watch GPS to calculate Speed and Bearing to a (pre-entered) GPS location. The problem I am experiencing is after some random time period the GPS stops providing updates.

I am running the App on a Samsung Galaxy Watch 4 and assume the reliability issue is related to the reported overheating issues with Samsung's latest watch

A fellow crew member suggested I try using the CPU clock speed to detect overheating. He points out many modern mobile devices lower their CPU clock speed when they detect they are getting too hot.

I hope to use CPU clock as an early warning of overheating. I can then slow down the rate of GPS updates allowing the App to retain reduced functionality which is far better than totally losing the GPS.

So can anyone provide a code snippet giving the CPU clock speed on an Android device?

EDIT #1

It is possible to obtain the thermal state of the CPU directly using the following code snippet

        val powerManager = getSystemService(Context.POWER_SERVICE) as PowerManager
        val thermalState = powerManager.currentThermalStatus
        /* Values
            THERMAL_STATUS_NONE,
            THERMAL_STATUS_LIGHT,
            THERMAL_STATUS_MODERATE,
            THERMAL_STATUS_SEVERE,
            THERMAL_STATUS_CRITICAL,
            THERMAL_STATUS_EMERGENCY,
            THERMAL_STATUS_SHUTDOWN,
         */

EDIT #2

The current working theory is this is probably not a watch overheating issue but a separate Galaxy Watch 4 "feature". Despite specifying the App as standalone the GPS updates stop when the connection with the phone is lost as discussed here

Notes:

I looked at measuring the execution time of the GPS calculations but this varies depending on the current heading. This is due to the need to handle "wrap" when averaging bearings, e.g. the average of a bearing of 3degrees and 359degrees is 1 degree (not 181degrees!)

Code available from Small Kotlin demo ACCESS_FINE_LOCATION

RatherBeSailing
  • 261
  • 1
  • 11
  • "I am running the App on a Samsung Galaxy Watch 4 and assume the reliability issue is related to the reported overheating issues with Samsung's latest watch" -- have you tried measuring the temperature, such as by using an IR thermometer, to confirm your theory? – CommonsWare Nov 05 '21 at 23:00
  • Since this is a fork of https://stackoverflow.com/questions/69735007/detect-samsung-galaxy-watch-4-overheating-issue-before-gps-updates-cease I suspect that there is something else going wrong. Getting GPS updates is a very common task for various Wear apps, and it works really well without overheating. The idea that you need to monitor CPU usage to get GPS updates working is certainly not the case. But without a reproducible sample, it's hard to help you with your original problem. This is what you should focus on. – Yuri Schimke Nov 06 '21 at 08:23
  • @CommonsWare the first time it happened the watch was noticeably warmer than usual. Friday night the App ran for around 45 minutes before the App reporting NO GPS and shortly afterwards the watch shut itself down despite only feeling slightly warmer than usual. Yesterday the App reported NO GPS after only 5 minutes of use and was no warmer than usual - watch never shut itself down. – RatherBeSailing Nov 07 '21 at 04:56
  • @YuriSchimke it worries me that my GPS code runs (all be it unreliably) on physical devices but will only run once on the emulator (the very first time - then it will never run again even if the app is uninstalled). When I added code to the earlier post the question was immediately marked as [closed] - so I am at a total loss as how to move forward. – RatherBeSailing Nov 07 '21 at 05:06
  • As I commented before, the way to get effective help on stackoverflow is to provide example code, preferably even a sample project in github that others could see anything obvious. – Yuri Schimke Nov 07 '21 at 12:29
  • @YuriSchimke the GPS code is available [here](https://stackoverflow.com/questions/69096969/small-kotlin-demo-access-fine-location) . The code only deepens the mystery - the code runs on an emulated (Pixel 5) or physical (LG V30+) phone . But when virtually the same code is targeted at watches it does not run on an emulated watch but does run (unreliably) on a physical watch (Samsung Galaxy Watch 4). – RatherBeSailing Nov 08 '21 at 02:52

1 Answers1

0

Not a definitive answer, I don't know the specific meaning of the values for your purpose.

From https://stackoverflow.com/a/3789655/1542667

And on Samsung Watch

wiseul:/ $ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq                                                                                                                                                   
200000
wiseul:/ $ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq                                                                                                                                                   
1200000
wiseul:/ $ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq                                                                                                                                                   
1200000
Yuri Schimke
  • 12,435
  • 3
  • 35
  • 69
  • Yuri thank you for the answer - unfortunately I had no luck finding the suggested files. Pity because monitoring cur_freq as a percentage of max_freq would be what I was looking for. – RatherBeSailing Nov 07 '21 at 05:27