'How do parental control apps lock the screen?

I am developing an app that locks the screen for some time, just like parental control apps do when the screen time runs out. However, I do not really know how they work. I suppose they don't use lockNow because there is that message that shows up telling you that the time has run out. I also don't think they use overlays, because the phone is supposed to detect the use of overlays. So does anybody know what kind of function is used?
Also for my app I want to add a button that ends the screen lock, so I am looking for a suitable way to achieve that.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source