I am writing a long-running background service that collects and analyzes device data. To do this I start a service, the service spawns a thread and the thread does the data collection / analysis.
From my reading I have learned that if I want the service to do it's thing while the screen is locked / device is sleeping, that I should be using a partial wakelock to ensure that the cpu does not go to sleep while the service's thread is running. However I'm really confused about this because I am currently not using a wakelock and am able to background my app or lock the screen or kill the app via the task manager and each time I do this I am able to observe via the logcat and Log statements that the thread that I spawned in the service is still running and doing the work that I want it to.
I've even run an adb shell dumpsys power and found that I have refcount = 0 for wakelocks which indicates to me that a different app isn't holding the wakelock for me.
Am I just getting lucky that my service seems to run just fine in the background without a wakelock?
Edit: The device has exhibited this behavior when connected to USB and when detached from USB. I have am periodically uploading the data that I collect to a server and have run tests where I never plug the device in and have the screen locked the entire test and I still am seeing that my thread runs and data gets uploaded.