Android AccessibilityService getEventTime() 时间格式

Android AccessibilityService getEventTime() time format

我在 Android 上使用 AccessibilityService 7。可以通过调用 getEventTime() 获取每个 AccessibilityEvent 的时间戳。根据文档,此方法 "Gets the time in which this event was sent".

有人知道 getEventTime() 中的 return 值指的是什么吗?好像不是Unix时间

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.

内部 AccessibilityManagerService 源代码。

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));
}

如您所见,在将事件发送到 UI 线程之前,它们将 SystemClock.uptimeMillis() 作为参数传递给 setEventType 方法。

Does somebody know what the return value from getEventTime() refers to?

getEventTime() 方法 return 传递给 setEventType(time) 方法的值。

SystemClock.uptimeMillis()

public static long uptimeMillis ()

Returns milliseconds since boot, not counting time spent in deep sleep.

更新:根据作者的问题

If I get the boot time and then add the uptimeMillis() is this equivalent to System.currentTimeMillis()?

不,不是。

来自 SystemClock android 文档。

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.

简而言之,SystemClock.uptimeMillis() returns 以毫秒为单位的启动时间,每次用户关闭 phone 并重新启动时都会重置。比如你给phone上电,10秒后调用这个方法就会return(10*1000=10000),20秒后就是20000等等。

另一方面,System.currentTimeMillis() 将从 Epoch time 开始 return 计时,以毫秒为单位。它会将当前日期时间转换为毫秒,因此如果您在设置中更改当前日期时间或使用 setCurrentTimeMillis(long) API.

,它将受到影响