I realise this is an old thread, but just an addition to it.
It is important to do the pw.ReleaseKeepAlive step when the app closes, otherwise the phone will remain in the 'KeepAlive' state until it is restarted. At least that is what I found.
Coupled this new found command with a CCTV example and needed to keep the camera active or it defeated the purpose of CCTV...