SECURITY ISSUE: I don't now how it happens, but readers of this questions come up with idea that solutions to this problem is a security threat. So please keep in mind, all data I am interested in is measuring time of user in/activity. That's all. What user did -- I am NOT interested at all!
What I need is very simple concept, but I cannot find a solution. I would like to run a process (in the background) and have a listener to user interaction.
So, user touches screen --> my method is triggered.
User unlock phone --> my method is triggered.
User types on physical keyboard --> my method is triggered.
So in short my method is NOT triggered when the phone lies still on the table :-) Please note, that the interaction is with entire phone, not with my app, and I am not interested that user typed letter "K", I am not even interested that user typed something, all I care is the user used the phone in some way.
Btw. the state when user is walking listening to music (phone in the pocket) -- it is NOT interaction.
What I am looking for is a trigger -- something like INTERACTION_DETECTED
, or (conversely) a callback method which is set like reportInactiveUser(10*1000)
and it would be called if user was inactive for 10 seconds.
QUESTION how to detect user interaction?
Purpose: to measure the time of using manually the phone.
(lack of) PROGRESS
I found out that BatteryStatsImpl
could hold the data I need. The instance of it is kept by BatteryStatsService
, which however does not let any access to it, only IBatteryStats
which in turn has only one interesting method -- getStatistics
and the output does not include user activity counters (or they are all zeros; I set all permissions on). So, so far -- bad luck.
All calls have to be made by reflection, because those classes are not available anyway ;-).