improve rotation handling

this commit was rewritten/inspired by one made to our jb 4.1 branch by sonicxml.

cheers buddy!

Change-Id: Ib3b46aa54e7bf6602f8c0557ed770624063af529
inputdevices: update from aosp (master)

Change-Id: If5fb11c354ea0144cdae1434de4c536302dda5b3