AccessibilityManagerService
This class is instantiated by the system as a system level service and
can be accessed only by the system. The task of this service is to be
a centralized event dispatch for {@link AccessibilityEvent}s generated
across all processes on the device. Events are dispatched to {@link
AccessibilityService}s.
Inside AccessibilityManagerService source code.
private void sendAccessibilityEventLocked(AccessibilityEvent event, int userId) {
// Resync to avoid calling out with the lock held
event.setEventTime(SystemClock.uptimeMillis());
mMainHandler.sendMessage(obtainMessage(
AccessibilityManagerService::sendAccessibilityEvent,
this, event, userId));
}
As you can see, before sending an event to UI thread, they pass SystemClock.uptimeMillis()
as param into setEventType
method.
Does somebody know what the return value from getEventTime() refers
to?
getEventTime()
method returns value which passed into setEventType(time)
method.
SystemClock.uptimeMillis()
public static long uptimeMillis ()
Returns milliseconds since boot, not counting time spent in deep
sleep.
Update: Based on the author's question
If I get the boot time and then add the uptimeMillis() is this
equivalent to System.currentTimeMillis()?
No, it is not.
From SystemClock android documentation.
SystemClock.uptimeMillis()
is counted in milliseconds since the system was booted. This clock
stops when the system enters deep sleep (CPU off, display dark, device
waiting for external input), but is not affected by clock scaling,
idle, or other power saving mechanisms
System.currentTimeMillis()
is the standard "wall" clock (time and date) expressing milliseconds
since the epoch. The wall clock can be set by the user or the phone
network (see setCurrentTimeMillis(long)), so the time may jump
backwards or forwards unpredictably. This clock should only be used
when correspondence with real-world dates and times is important, such
as in a calendar or alarm clock application. Interval or elapsed time
measurements should use a different clock. If you are using
System.currentTimeMillis(), consider listening to the
ACTION_TIME_TICK, ACTION_TIME_CHANGED and ACTION_TIMEZONE_CHANGED
Intent broadcasts to find out when the time changes.
In short, SystemClock.uptimeMillis()
returns time from boot in milliseconds, it will be reset each time users power off the phone and reboot again. For example, you power on the phone, after 10 seconds, if you call this method, it will return (10 * 1000 = 10000), after 20 seconds, it will be 20000 and so on.
In the other hand, System.currentTimeMillis()
will return time from Epoch time in milliseconds. It will convert the current date time into milliseconds so it will be effected if you change current date time in settings or using setCurrentTimeMillis(long)
API.