Skip to content

Commit b11499d

Browse files
author
Jeff Brown
committed
Make InputEvent.getEventTime() public.
Also add new methods to access the event timestamp in nanoseconds. Hidden for now but useful for prototyping. Bug: 6374616 Change-Id: I7030734a908e8e31a17a356debc269db7c0f0783
1 parent 5bbd4b4 commit b11499d

File tree

4 files changed

+86
-7
lines changed

4 files changed

+86
-7
lines changed

api/current.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22716,6 +22716,7 @@ package android.view {
2271622716
method public int describeContents();
2271722717
method public final android.view.InputDevice getDevice();
2271822718
method public abstract int getDeviceId();
22719+
method public abstract long getEventTime();
2271922720
method public abstract int getSource();
2272022721
field public static final android.os.Parcelable.Creator CREATOR;
2272122722
}

core/java/android/view/InputEvent.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,26 @@ protected void prepareForReuse() {
159159
public abstract void setTainted(boolean tainted);
160160

161161
/**
162-
* Returns the time (in ns) when this specific event was generated.
162+
* Retrieve the time this event occurred,
163+
* in the {@link android.os.SystemClock#uptimeMillis} time base.
164+
*
165+
* @return Returns the time this event occurred,
166+
* in the {@link android.os.SystemClock#uptimeMillis} time base.
167+
*/
168+
public abstract long getEventTime();
169+
170+
/**
171+
* Retrieve the time this event occurred,
172+
* in the {@link android.os.SystemClock#uptimeMillis} time base but with
173+
* nanosecond (instead of millisecond) precision.
174+
* <p>
163175
* The value is in nanosecond precision but it may not have nanosecond accuracy.
176+
* </p>
177+
*
178+
* @return Returns the time this event occurred,
179+
* in the {@link android.os.SystemClock#uptimeMillis} time base but with
180+
* nanosecond (instead of millisecond) precision.
181+
*
164182
* @hide
165183
*/
166184
public abstract long getEventTimeNano();

core/java/android/view/KeyEvent.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2375,17 +2375,31 @@ public final long getDownTime() {
23752375
}
23762376

23772377
/**
2378-
* Retrieve the time this event occurred,
2378+
* Retrieve the time this event occurred,
23792379
* in the {@link android.os.SystemClock#uptimeMillis} time base.
2380-
*
2380+
*
23812381
* @return Returns the time this event occurred,
23822382
* in the {@link android.os.SystemClock#uptimeMillis} time base.
23832383
*/
2384+
@Override
23842385
public final long getEventTime() {
23852386
return mEventTime;
23862387
}
23872388

2388-
/** @hide */
2389+
/**
2390+
* Retrieve the time this event occurred,
2391+
* in the {@link android.os.SystemClock#uptimeMillis} time base but with
2392+
* nanosecond (instead of millisecond) precision.
2393+
* <p>
2394+
* The value is in nanosecond precision but it may not have nanosecond accuracy.
2395+
* </p>
2396+
*
2397+
* @return Returns the time this event occurred,
2398+
* in the {@link android.os.SystemClock#uptimeMillis} time base but with
2399+
* nanosecond (instead of millisecond) precision.
2400+
*
2401+
* @hide
2402+
*/
23892403
@Override
23902404
public final long getEventTimeNano() {
23912405
return mEventTime * 1000000L;

core/java/android/view/MotionEvent.java

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,18 +1781,32 @@ public final void setDownTime(long downTime) {
17811781
}
17821782

17831783
/**
1784-
* Returns the time (in ms) when this specific event was generated.
1784+
* Retrieve the time this event occurred,
1785+
* in the {@link android.os.SystemClock#uptimeMillis} time base.
1786+
*
1787+
* @return Returns the time this event occurred,
1788+
* in the {@link android.os.SystemClock#uptimeMillis} time base.
17851789
*/
1790+
@Override
17861791
public final long getEventTime() {
17871792
return nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT) / NS_PER_MS;
17881793
}
17891794

17901795
/**
1791-
* Returns the time (in ns) when this specific event was generated.
1796+
* Retrieve the time this event occurred,
1797+
* in the {@link android.os.SystemClock#uptimeMillis} time base but with
1798+
* nanosecond precision.
1799+
* <p>
17921800
* The value is in nanosecond precision but it may not have nanosecond accuracy.
1801+
* </p>
1802+
*
1803+
* @return Returns the time this event occurred,
1804+
* in the {@link android.os.SystemClock#uptimeMillis} time base but with
1805+
* nanosecond precision.
17931806
*
17941807
* @hide
17951808
*/
1809+
@Override
17961810
public final long getEventTimeNano() {
17971811
return nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT);
17981812
}
@@ -2234,10 +2248,16 @@ public final int getHistorySize() {
22342248

22352249
/**
22362250
* Returns the time that a historical movement occurred between this event
2237-
* and the previous event. Only applies to ACTION_MOVE events.
2251+
* and the previous event, in the {@link android.os.SystemClock#uptimeMillis} time base.
2252+
* <p>
2253+
* This only applies to ACTION_MOVE events.
2254+
* </p>
22382255
*
22392256
* @param pos Which historical value to return; must be less than
22402257
* {@link #getHistorySize}
2258+
* @return Returns the time that a historical movement occurred between this
2259+
* event and the previous event,
2260+
* in the {@link android.os.SystemClock#uptimeMillis} time base.
22412261
*
22422262
* @see #getHistorySize
22432263
* @see #getEventTime
@@ -2246,6 +2266,32 @@ public final long getHistoricalEventTime(int pos) {
22462266
return nativeGetEventTimeNanos(mNativePtr, pos) / NS_PER_MS;
22472267
}
22482268

2269+
/**
2270+
* Returns the time that a historical movement occurred between this event
2271+
* and the previous event, in the {@link android.os.SystemClock#uptimeMillis} time base
2272+
* but with nanosecond (instead of millisecond) precision.
2273+
* <p>
2274+
* This only applies to ACTION_MOVE events.
2275+
* </p><p>
2276+
* The value is in nanosecond precision but it may not have nanosecond accuracy.
2277+
* </p>
2278+
*
2279+
* @param pos Which historical value to return; must be less than
2280+
* {@link #getHistorySize}
2281+
* @return Returns the time that a historical movement occurred between this
2282+
* event and the previous event,
2283+
* in the {@link android.os.SystemClock#uptimeMillis} time base but with
2284+
* nanosecond (instead of millisecond) precision.
2285+
*
2286+
* @see #getHistorySize
2287+
* @see #getEventTime
2288+
*
2289+
* @hide
2290+
*/
2291+
public final long getHistoricalEventTimeNano(int pos) {
2292+
return nativeGetEventTimeNanos(mNativePtr, pos);
2293+
}
2294+
22492295
/**
22502296
* {@link #getHistoricalX(int, int)} for the first pointer index (may be an
22512297
* arbitrary pointer identifier).

0 commit comments

Comments
 (0)