Timer based on when Screen Unlocks and Locks


Hi All
I am making an app where I want to create timer which starts when mobile screen unlocks and stops when screen locks. This way I want to monitor how much time I used my phone

I know its very basic and many apps are available but since I love to code so I want to create it by myself.

Can anyone help?