Issue
I'm running a python script in the background (using nohup) on the android device (which is rooted ofcourse).
The script gets battery data using dumpsys and writes this out to a file with a timestamp. The script runs fine as long as the phone is connected to my laptop. As soon as I disconnect it, the script pauses. That is, once I reconnect, it starts writing to the file once again. I saw this as there is a gap in the timestamps being written to the file from when I disconnect and reconnect it.
Any ideas what might be causing the script to pause?
Solution
Turns out I just need to get the wake lock. No other way around it.
So to get the wake lock from my python script, I write a string to
/sys/power/wake_lock.
This grabs the partial wake lock. Once I'm done, in order to release the wake lock, I write the exact same string to
/sys/power/wake_unlock.
This fixes the issue as the CPU does not go to sleep.
Answered By - AsadSMalik Answer Checked By - Marilyn (WPSolving Volunteer)