Change power state level when app goes in background/foreground

This code shows how to change power state level when app goes in background/foreground using visibilitychange event. When app in foreground and SCREEN_NORMAL state is requested, the device does not turn off screen automatically.