From 956c5df188cc94b1f578f6fb91ebd467d93ea459 Mon Sep 17 00:00:00 2001
From: Chris Ye
Date: Tue, 26 Jan 2021 13:21:01 -0800
Subject: Update SOURCE_SENSOR source for input device.
Update the SOURCE_SENSOR input source to not limited to Joystick deivce
class.
Bug: 170131554
Test: atest InputDeviceSensorManagerTest
Change-Id: I08cb72f22d9a06f63139317551c821fd5eaa3e46
---
include/android/input.h | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
(limited to 'include/android')
diff --git a/include/android/input.h b/include/android/input.h
index b5d399ee09..b70d42427d 100644
--- a/include/android/input.h
+++ b/include/android/input.h
@@ -856,8 +856,10 @@ enum {
AINPUT_SOURCE_TOUCH_NAVIGATION = 0x00200000 | AINPUT_SOURCE_CLASS_NONE,
/** joystick */
AINPUT_SOURCE_JOYSTICK = 0x01000000 | AINPUT_SOURCE_CLASS_JOYSTICK,
+ /** HDMI */
+ AINPUT_SOURCE_HDMI = 0x02000000 | AINPUT_SOURCE_CLASS_BUTTON,
/** sensor */
- AINPUT_SOURCE_SENSOR = 0x02000000 | AINPUT_SOURCE_CLASS_JOYSTICK,
+ AINPUT_SOURCE_SENSOR = 0x04000000 | AINPUT_SOURCE_UNKNOWN,
/** rotary encoder */
AINPUT_SOURCE_ROTARY_ENCODER = 0x00400000 | AINPUT_SOURCE_CLASS_NONE,
--
cgit v1.2.3-59-g8ed1b
From 4d08ae78c2654f198264ae4a85cc7686dff46291 Mon Sep 17 00:00:00 2001
From: Elliott Hughes
Date: Tue, 26 Jan 2021 14:55:48 -0800
Subject: Remove __ANDROID_API__ #if checks.
__INTRODUCED_IN() does the right thing automatically now.
Bug: http://b/178449269
Test: treehugger
Change-Id: I94d2ad6fafb6d907793a416db82a9e56f4f61d1c
---
include/android/bitmap.h | 8 ------
include/android/choreographer.h | 11 --------
include/android/configuration.h | 4 ---
include/android/font.h | 4 ---
include/android/font_matcher.h | 4 ---
include/android/imagedecoder.h | 32 ----------------------
include/android/multinetwork.h | 8 ------
include/android/native_window_jni.h | 2 --
include/android/sensor.h | 27 ++++++------------
include/android/sharedmem.h | 4 ---
include/android/sharedmem_jni.h | 4 ---
include/android/surface_control.h | 11 --------
include/android/surface_texture.h | 4 ---
include/android/surface_texture_jni.h | 4 ---
include/android/system_fonts.h | 4 ---
include/android/trace.h | 8 ------
.../nativewindow/include/android/hardware_buffer.h | 11 --------
libs/nativewindow/include/android/native_window.h | 18 +-----------
18 files changed, 9 insertions(+), 159 deletions(-)
(limited to 'include/android')
diff --git a/include/android/bitmap.h b/include/android/bitmap.h
index d7f25e1858..2362c9e491 100644
--- a/include/android/bitmap.h
+++ b/include/android/bitmap.h
@@ -132,8 +132,6 @@ typedef struct {
int AndroidBitmap_getInfo(JNIEnv* env, jobject jbitmap,
AndroidBitmapInfo* info);
-#if __ANDROID_API__ >= 30
-
/**
* Given a java bitmap object, return its {@link ADataSpace}.
*
@@ -145,8 +143,6 @@ int AndroidBitmap_getInfo(JNIEnv* env, jobject jbitmap,
*/
int32_t AndroidBitmap_getDataSpace(JNIEnv* env, jobject jbitmap) __INTRODUCED_IN(30);
-#endif // __ANDROID_API__ >= 30
-
/**
* Given a java bitmap object, attempt to lock the pixel address.
* Locking will ensure that the memory for the pixels will not move
@@ -216,8 +212,6 @@ typedef bool (*AndroidBitmap_CompressWriteFunc)(void* userContext,
const void* data,
size_t size) __INTRODUCED_IN(30);
-#if __ANDROID_API__ >= 30
-
/**
* Compress |pixels| as described by |info|.
*
@@ -269,8 +263,6 @@ typedef struct AHardwareBuffer AHardwareBuffer;
int AndroidBitmap_getHardwareBuffer(JNIEnv* env, jobject bitmap,
AHardwareBuffer** outBuffer) __INTRODUCED_IN(30);
-#endif // __ANDROID_API__ >= 30
-
#ifdef __cplusplus
}
#endif
diff --git a/include/android/choreographer.h b/include/android/choreographer.h
index e9f559cd8e..8039bb0d79 100644
--- a/include/android/choreographer.h
+++ b/include/android/choreographer.h
@@ -61,8 +61,6 @@ typedef void (*AChoreographer_frameCallback64)(int64_t frameTimeNanos, void* dat
*/
typedef void (*AChoreographer_refreshRateCallback)(int64_t vsyncPeriodNanos, void* data);
-#if __ANDROID_API__ >= 24
-
/**
* Get the AChoreographer instance for the current thread. This must be called
* on an ALooper thread.
@@ -86,10 +84,6 @@ void AChoreographer_postFrameCallbackDelayed(AChoreographer* choreographer,
long delayMillis) __INTRODUCED_IN(24)
__DEPRECATED_IN(29);
-#endif /* __ANDROID_API__ >= 24 */
-
-#if __ANDROID_API__ >= 29
-
/**
* Power a callback to be run on the next frame. The data pointer provided will
* be passed to the callback function when it's called.
@@ -111,10 +105,6 @@ void AChoreographer_postFrameCallbackDelayed64(AChoreographer* choreographer,
AChoreographer_frameCallback64 callback, void* data,
uint32_t delayMillis) __INTRODUCED_IN(29);
-#endif /* __ANDROID_API__ >= 29 */
-
-#if __ANDROID_API__ >= 30
-
/**
* Registers a callback to be run when the display refresh rate changes. The
* data pointer provided will be passed to the callback function when it's
@@ -160,7 +150,6 @@ void AChoreographer_registerRefreshRateCallback(AChoreographer* choreographer,
void AChoreographer_unregisterRefreshRateCallback(AChoreographer* choreographer,
AChoreographer_refreshRateCallback, void* data)
__INTRODUCED_IN(30);
-#endif /* __ANDROID_API__ >= 30 */
__END_DECLS
diff --git a/include/android/configuration.h b/include/android/configuration.h
index ccf3e59066..88019ae054 100644
--- a/include/android/configuration.h
+++ b/include/android/configuration.h
@@ -645,14 +645,12 @@ int32_t AConfiguration_getScreenLong(AConfiguration* config);
*/
void AConfiguration_setScreenLong(AConfiguration* config, int32_t screenLong);
-#if __ANDROID_API__ >= 30
/**
* Return the current ACONFIGURATION_SCREENROUND_* set in the configuration.
*
* Available since API level 30.
*/
int32_t AConfiguration_getScreenRound(AConfiguration* config) __INTRODUCED_IN(30);
-#endif
/**
* Set the current screen round in the configuration.
@@ -712,7 +710,6 @@ int32_t AConfiguration_getSmallestScreenWidthDp(AConfiguration* config);
*/
void AConfiguration_setSmallestScreenWidthDp(AConfiguration* config, int32_t value);
-#if __ANDROID_API__ >= 17
/**
* Return the configuration's layout direction, or
* ACONFIGURATION_LAYOUTDIR_ANY if not set.
@@ -727,7 +724,6 @@ int32_t AConfiguration_getLayoutDirection(AConfiguration* config) __INTRODUCED_I
* Available since API level 17.
*/
void AConfiguration_setLayoutDirection(AConfiguration* config, int32_t value) __INTRODUCED_IN(17);
-#endif /* __ANDROID_API__ >= 17 */
/**
* Perform a diff between two configurations. Returns a bit mask of
diff --git a/include/android/font.h b/include/android/font.h
index 1618096d69..a172618829 100644
--- a/include/android/font.h
+++ b/include/android/font.h
@@ -51,8 +51,6 @@
__BEGIN_DECLS
-#if __ANDROID_API__ >= 29
-
enum {
/** The minimum value fot the font weight value. */
AFONT_WEIGHT_MIN = 0,
@@ -297,8 +295,6 @@ uint32_t AFont_getAxisTag(const AFont* _Nonnull font, uint32_t axisIndex)
float AFont_getAxisValue(const AFont* _Nonnull font, uint32_t axisIndex)
__INTRODUCED_IN(29);
-#endif // __ANDROID_API__ >= 29
-
__END_DECLS
#endif // ANDROID_FONT_H
diff --git a/include/android/font_matcher.h b/include/android/font_matcher.h
index d4bd892bf6..49e478c2f3 100644
--- a/include/android/font_matcher.h
+++ b/include/android/font_matcher.h
@@ -97,8 +97,6 @@
__BEGIN_DECLS
-#if __ANDROID_API__ >= 29
-
enum {
/** A family variant value for the system default variant. */
AFAMILY_VARIANT_DEFAULT = 0,
@@ -217,8 +215,6 @@ AFont* _Nonnull AFontMatcher_match(
const uint32_t textLength,
uint32_t* _Nullable runLengthOut) __INTRODUCED_IN(29);
-#endif // __ANDROID_API__ >= 29
-
__END_DECLS
#endif // ANDROID_FONT_MATCHER_H
diff --git a/include/android/imagedecoder.h b/include/android/imagedecoder.h
index c7a8939766..819a6a4c1f 100644
--- a/include/android/imagedecoder.h
+++ b/include/android/imagedecoder.h
@@ -139,8 +139,6 @@ enum {
ANDROID_IMAGE_DECODER_INVALID_STATE = -11,
};
-#if __ANDROID_API__ >= 31
-
/**
* Return a constant string value representing the error code.
*
@@ -155,8 +153,6 @@ enum {
*/
const char* _Nullable AImageDecoder_resultToString(int)__INTRODUCED_IN(31);
-#endif // __ANDROID_API__ >= 31
-
struct AImageDecoder;
/**
@@ -179,8 +175,6 @@ struct AImageDecoder;
*/
typedef struct AImageDecoder AImageDecoder;
-#if __ANDROID_API__ >= 30
-
/**
* Create a new {@link AImageDecoder} from an {@link AAsset}.
*
@@ -469,8 +463,6 @@ int AImageDecoder_computeSampledSize(const AImageDecoder* _Nonnull decoder, int
*/
int AImageDecoder_setCrop(AImageDecoder* _Nonnull decoder, ARect crop) __INTRODUCED_IN(30);
-#endif // __ANDROID_API__ >= 30
-
struct AImageDecoderHeaderInfo;
/**
* Opaque handle for representing information about the encoded image.
@@ -483,8 +475,6 @@ struct AImageDecoderHeaderInfo;
*/
typedef struct AImageDecoderHeaderInfo AImageDecoderHeaderInfo;
-#if __ANDROID_API__ >= 30
-
/**
* Return an opaque handle for reading header info.
*
@@ -672,10 +662,6 @@ int AImageDecoder_decodeImage(AImageDecoder* _Nonnull decoder,
void* _Nonnull pixels, size_t stride,
size_t size) __INTRODUCED_IN(30);
-#endif // __ANDROID_API__ >= 30
-
-#if __ANDROID_API__ >= 31
-
/**
* Return true iff the image is animated - i.e. has multiple frames.
*
@@ -690,8 +676,6 @@ int AImageDecoder_decodeImage(AImageDecoder* _Nonnull decoder,
bool AImageDecoder_isAnimated(AImageDecoder* _Nonnull decoder)
__INTRODUCED_IN(31);
-#endif // __ANDROID_API__ >= 31
-
enum {
/*
* Reported by {@link AImageDecoder_getRepeatCount} if the
@@ -702,8 +686,6 @@ enum {
ANDROID_IMAGE_DECODER_INFINITE = INT32_MAX,
};
-#if __ANDROID_API__ >= 31
-
/**
* Report how many times the animation should repeat.
*
@@ -793,8 +775,6 @@ int AImageDecoder_advanceFrame(AImageDecoder* _Nonnull decoder)
int AImageDecoder_rewind(AImageDecoder* _Nonnull decoder)
__INTRODUCED_IN(31);
-#endif // __ANDROID_API__ >= 31
-
struct AImageDecoderFrameInfo;
/**
@@ -810,8 +790,6 @@ struct AImageDecoderFrameInfo;
*/
typedef struct AImageDecoderFrameInfo AImageDecoderFrameInfo;
-#if __ANDROID_API__ >= 31
-
/**
* Create an uninitialized AImageDecoderFrameInfo.
*
@@ -922,8 +900,6 @@ ARect AImageDecoderFrameInfo_getFrameRect(
bool AImageDecoderFrameInfo_hasAlphaWithinBounds(
const AImageDecoderFrameInfo* _Nonnull info) __INTRODUCED_IN(31);
-#endif // __ANDROID_API__ >= 31
-
/**
* How a frame is “disposed” before showing the next one.
*
@@ -947,8 +923,6 @@ enum {
ANDROID_IMAGE_DECODER_DISPOSE_OP_PREVIOUS = 3,
};
-#if __ANDROID_API__ >= 31
-
/**
* Return how this frame is “disposed” before showing the next one.
*
@@ -969,8 +943,6 @@ enum {
int32_t AImageDecoderFrameInfo_getDisposeOp(
const AImageDecoderFrameInfo* _Nonnull info) __INTRODUCED_IN(31);
-#endif // __ANDROID_API__ >= 31
-
/**
* How a frame is blended with the previous frame.
*
@@ -989,8 +961,6 @@ enum {
ANDROID_IMAGE_DECODER_BLEND_OP_SRC_OVER = 2,
};
-#if __ANDROID_API__ >= 31
-
/**
* Return how this frame is blended with the previous frame.
*
@@ -1047,8 +1017,6 @@ void AImageDecoder_setInternallyHandleDisposePrevious(
__INTRODUCED_IN(31);
-#endif // __ANDROID_API__ >= 31
-
#ifdef __cplusplus
}
#endif
diff --git a/include/android/multinetwork.h b/include/android/multinetwork.h
index c6d1c94c0a..424299d664 100644
--- a/include/android/multinetwork.h
+++ b/include/android/multinetwork.h
@@ -60,8 +60,6 @@ typedef uint64_t net_handle_t;
* on failure with an appropriate errno value set.
*/
-#if __ANDROID_API__ >= 23
-
/**
* Set the network to be used by the given socket file descriptor.
*
@@ -111,10 +109,6 @@ int android_getaddrinfofornetwork(net_handle_t network,
const char *node, const char *service,
const struct addrinfo *hints, struct addrinfo **res) __INTRODUCED_IN(23);
-#endif /* __ANDROID_API__ >= 23 */
-
-#if __ANDROID_API__ >= 29
-
/**
* Possible values of the flags argument to android_res_nsend and android_res_nquery.
* Values are ORed together.
@@ -187,8 +181,6 @@ int android_res_nresult(int fd,
*/
void android_res_cancel(int nsend_fd) __INTRODUCED_IN(29);
-#endif /* __ANDROID_API__ >= 29 */
-
__END_DECLS
#endif // ANDROID_MULTINETWORK_H
diff --git a/include/android/native_window_jni.h b/include/android/native_window_jni.h
index 3a77ffe86b..071ec798b4 100644
--- a/include/android/native_window_jni.h
+++ b/include/android/native_window_jni.h
@@ -44,7 +44,6 @@ extern "C" {
*/
ANativeWindow* ANativeWindow_fromSurface(JNIEnv* env, jobject surface);
-#if __ANDROID_API__ >= 26
/**
* Return a Java Surface object derived from the ANativeWindow, for interacting
* with it through Java code. The returned Java object acquires a reference on
@@ -55,7 +54,6 @@ ANativeWindow* ANativeWindow_fromSurface(JNIEnv* env, jobject surface);
* Available since API level 26.
*/
jobject ANativeWindow_toSurface(JNIEnv* env, ANativeWindow* window) __INTRODUCED_IN(26);
-#endif
#ifdef __cplusplus
};
diff --git a/include/android/sensor.h b/include/android/sensor.h
index eb407794d1..6447844b06 100644
--- a/include/android/sensor.h
+++ b/include/android/sensor.h
@@ -52,6 +52,13 @@
#include
#include
+#if !defined(__INTRODUCED_IN)
+#define __INTRODUCED_IN(__api_level) /* nothing */
+#endif
+#if !defined(__DEPRECATED_IN)
+#define __DEPRECATED_IN(__api_level) __attribute__((__deprecated__))
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -553,13 +560,8 @@ typedef ASensorRef const* ASensorList;
* ASensorManager* sensorManager = ASensorManager_getInstance();
*
*/
-#if __ANDROID_API__ >= 26
-__attribute__ ((deprecated)) ASensorManager* ASensorManager_getInstance();
-#else
-ASensorManager* ASensorManager_getInstance();
-#endif
+ASensorManager* ASensorManager_getInstance() __DEPRECATED_IN(26);
-#if __ANDROID_API__ >= 26
/**
* Get a reference to the sensor manager. ASensorManager is a singleton
* per package as different packages may have access to different sensors.
@@ -571,7 +573,6 @@ ASensorManager* ASensorManager_getInstance();
* Available since API level 26.
*/
ASensorManager* ASensorManager_getInstanceForPackage(const char* packageName) __INTRODUCED_IN(26);
-#endif
/**
* Returns the list of available sensors.
@@ -584,7 +585,6 @@ int ASensorManager_getSensorList(ASensorManager* manager, ASensorList* list);
*/
ASensor const* ASensorManager_getDefaultSensor(ASensorManager* manager, int type);
-#if __ANDROID_API__ >= 21
/**
* Returns the default sensor with the given type and wakeUp properties or NULL if no sensor
* of this type and wakeUp properties exists.
@@ -592,7 +592,6 @@ ASensor const* ASensorManager_getDefaultSensor(ASensorManager* manager, int type
* Available since API level 21.
*/
ASensor const* ASensorManager_getDefaultSensorEx(ASensorManager* manager, int type, bool wakeUp) __INTRODUCED_IN(21);
-#endif
/**
* Creates a new sensor event queue and associate it with a looper.
@@ -609,7 +608,6 @@ ASensorEventQueue* ASensorManager_createEventQueue(ASensorManager* manager,
*/
int ASensorManager_destroyEventQueue(ASensorManager* manager, ASensorEventQueue* queue);
-#if __ANDROID_API__ >= 26
/**
* Create direct channel based on shared memory
*
@@ -706,7 +704,6 @@ void ASensorManager_destroyDirectChannel(ASensorManager* manager, int channelId)
*/
int ASensorManager_configureDirectReport(ASensorManager* manager,
ASensor const* sensor, int channelId, int rate) __INTRODUCED_IN(26);
-#endif /* __ANDROID_API__ >= 26 */
/*****************************************************************************/
@@ -795,7 +792,6 @@ int ASensorEventQueue_hasEvents(ASensorEventQueue* queue);
*/
ssize_t ASensorEventQueue_getEvents(ASensorEventQueue* queue, ASensorEvent* events, size_t count);
-#if __ANDROID_API__ >= 29
/**
* Request that {@link ASENSOR_TYPE_ADDITIONAL_INFO} events to be delivered on
* the given {@link ASensorEventQueue}.
@@ -819,7 +815,6 @@ ssize_t ASensorEventQueue_getEvents(ASensorEventQueue* queue, ASensorEvent* even
* \return 0 on success or a negative error code on failure
*/
int ASensorEventQueue_requestAdditionalInfoEvents(ASensorEventQueue* queue, bool enable) __INTRODUCED_IN(29);
-#endif /* __ANDROID_API__ >= 29 */
/*****************************************************************************/
@@ -850,7 +845,6 @@ float ASensor_getResolution(ASensor const* sensor);
*/
int ASensor_getMinDelay(ASensor const* sensor);
-#if __ANDROID_API__ >= 21
/**
* Returns the maximum size of batches for this sensor. Batches will often be
* smaller, as the hardware fifo might be used for other sensors.
@@ -886,9 +880,7 @@ int ASensor_getReportingMode(ASensor const* sensor) __INTRODUCED_IN(21);
* Available since API level 21.
*/
bool ASensor_isWakeUpSensor(ASensor const* sensor) __INTRODUCED_IN(21);
-#endif /* __ANDROID_API__ >= 21 */
-#if __ANDROID_API__ >= 26
/**
* Test if sensor supports a certain type of direct channel.
*
@@ -914,9 +906,7 @@ bool ASensor_isDirectChannelTypeSupported(ASensor const* sensor, int channelType
* does not support direct report.
*/
int ASensor_getHighestDirectReportRateLevel(ASensor const* sensor) __INTRODUCED_IN(26);
-#endif /* __ANDROID_API__ >= 26 */
-#if __ANDROID_API__ >= 29
/**
* Returns the sensor's handle.
*
@@ -934,7 +924,6 @@ int ASensor_getHighestDirectReportRateLevel(ASensor const* sensor) __INTRODUCED_
* Available since API level 29.
*/
int ASensor_getHandle(ASensor const* sensor) __INTRODUCED_IN(29);
-#endif /* __ANDROID_API__ >= 29 */
#ifdef __cplusplus
};
diff --git a/include/android/sharedmem.h b/include/android/sharedmem.h
index 5f74682b40..7994aa9914 100644
--- a/include/android/sharedmem.h
+++ b/include/android/sharedmem.h
@@ -50,8 +50,6 @@
extern "C" {
#endif
-#if __ANDROID_API__ >= 26
-
/**
* Create a shared memory region.
*
@@ -121,8 +119,6 @@ size_t ASharedMemory_getSize(int fd) __INTRODUCED_IN(26);
*/
int ASharedMemory_setProt(int fd, int prot) __INTRODUCED_IN(26);
-#endif // __ANDROID_API__ >= 26
-
#ifdef __cplusplus
};
#endif
diff --git a/include/android/sharedmem_jni.h b/include/android/sharedmem_jni.h
index 13e56e6f09..bbac785a33 100644
--- a/include/android/sharedmem_jni.h
+++ b/include/android/sharedmem_jni.h
@@ -52,8 +52,6 @@
extern "C" {
#endif
-#if __ANDROID_API__ >= 27
-
/**
* Returns a dup'd FD from the given Java android.os.SharedMemory object. The returned file
* descriptor has all the same properties & capabilities as the FD returned from
@@ -72,8 +70,6 @@ extern "C" {
*/
int ASharedMemory_dupFromJava(JNIEnv* env, jobject sharedMemory) __INTRODUCED_IN(27);
-#endif // __ANDROID_API__ >= 27
-
#ifdef __cplusplus
};
#endif
diff --git a/include/android/surface_control.h b/include/android/surface_control.h
index 7a7424833b..98fd875968 100644
--- a/include/android/surface_control.h
+++ b/include/android/surface_control.h
@@ -35,8 +35,6 @@
__BEGIN_DECLS
-#if __ANDROID_API__ >= 29
-
struct ASurfaceControl;
/**
@@ -409,10 +407,6 @@ void ASurfaceTransaction_setHdrMetadata_cta861_3(ASurfaceTransaction* transactio
struct AHdrMetadata_cta861_3* metadata)
__INTRODUCED_IN(29);
-#endif // __ANDROID_API__ >= 29
-
-#if __ANDROID_API__ >= 30
-
/**
* Same as ASurfaceTransaction_setFrameRateWithSeamlessness(transaction, surface_control,
* frameRate, compatibility, true).
@@ -425,10 +419,6 @@ void ASurfaceTransaction_setFrameRate(ASurfaceTransaction* transaction,
ASurfaceControl* surface_control, float frameRate,
int8_t compatibility) __INTRODUCED_IN(30);
-#endif // __ANDROID_API__ >= 30
-
-#if __ANDROID_API__ >= 31
-
/**
* Sets the intended frame rate for \a surface_control.
*
@@ -462,7 +452,6 @@ void ASurfaceTransaction_setFrameRateWithSeamlessness(ASurfaceTransaction* trans
int8_t compatibility, bool shouldBeSeamless)
__INTRODUCED_IN(31);
-#endif // __ANDROID_API__ >= 31
__END_DECLS
#endif // ANDROID_SURFACE_CONTROL_H
diff --git a/include/android/surface_texture.h b/include/android/surface_texture.h
index dde7eaa0b6..b227b324f8 100644
--- a/include/android/surface_texture.h
+++ b/include/android/surface_texture.h
@@ -59,8 +59,6 @@ struct ASurfaceTexture;
*/
typedef struct ASurfaceTexture ASurfaceTexture;
-#if __ANDROID_API__ >= 28
-
/**
* Release the reference to the native ASurfaceTexture acquired with
* ASurfaceTexture_fromSurfaceTexture().
@@ -175,8 +173,6 @@ void ASurfaceTexture_getTransformMatrix(ASurfaceTexture* st, float mtx[16]) __IN
*/
int64_t ASurfaceTexture_getTimestamp(ASurfaceTexture* st) __INTRODUCED_IN(28);
-#endif /* __ANDROID_API__ >= 28 */
-
__END_DECLS
#endif /* ANDROID_NATIVE_SURFACE_TEXTURE_H */
diff --git a/include/android/surface_texture_jni.h b/include/android/surface_texture_jni.h
index 2266d541f6..e40686d96c 100644
--- a/include/android/surface_texture_jni.h
+++ b/include/android/surface_texture_jni.h
@@ -32,8 +32,6 @@
__BEGIN_DECLS
-#if __ANDROID_API__ >= 28
-
/**
* Get a reference to the native ASurfaceTexture from the corresponding java object.
*
@@ -52,8 +50,6 @@ __BEGIN_DECLS
*/
ASurfaceTexture* ASurfaceTexture_fromSurfaceTexture(JNIEnv* env, jobject surfacetexture) __INTRODUCED_IN(28);
-#endif
-
__END_DECLS
#endif /* ANDROID_NATIVE_SURFACE_TEXTURE_JNI_H */
diff --git a/include/android/system_fonts.h b/include/android/system_fonts.h
index 6fd7d2c0ab..b0bbb954a9 100644
--- a/include/android/system_fonts.h
+++ b/include/android/system_fonts.h
@@ -87,8 +87,6 @@
__BEGIN_DECLS
-#if __ANDROID_API__ >= 29
-
/**
* ASystemFontIterator provides access to the system font configuration.
*
@@ -128,8 +126,6 @@ void ASystemFontIterator_close(ASystemFontIterator* _Nullable iterator) __INTROD
*/
AFont* _Nullable ASystemFontIterator_next(ASystemFontIterator* _Nonnull iterator) __INTRODUCED_IN(29);
-#endif // __ANDROID_API__ >= 29
-
__END_DECLS
#endif // ANDROID_SYSTEM_FONTS_H
diff --git a/include/android/trace.h b/include/android/trace.h
index dbad6f6f21..dcefffb20d 100644
--- a/include/android/trace.h
+++ b/include/android/trace.h
@@ -40,8 +40,6 @@
extern "C" {
#endif
-#if __ANDROID_API__ >= 23
-
/**
* Returns true if tracing is enabled. Use this to avoid expensive computation only necessary
* when tracing is enabled.
@@ -72,10 +70,6 @@ void ATrace_beginSection(const char* sectionName) __INTRODUCED_IN(23);
*/
void ATrace_endSection() __INTRODUCED_IN(23);
-#endif /* __ANDROID_API__ >= 23 */
-
-#if __ANDROID_API__ >= 29
-
/**
* Writes a trace message to indicate that a given section of code has
* begun. Must be followed by a call to {@link ATrace_endAsyncSection} with the same
@@ -112,8 +106,6 @@ void ATrace_endAsyncSection(const char* sectionName, int32_t cookie) __INTRODUCE
*/
void ATrace_setCounter(const char* counterName, int64_t counterValue) __INTRODUCED_IN(29);
-#endif /* __ANDROID_API__ >= 29 */
-
#ifdef __cplusplus
}
#endif
diff --git a/libs/nativewindow/include/android/hardware_buffer.h b/libs/nativewindow/include/android/hardware_buffer.h
index 4fcca9e1d3..6ecb83ae0d 100644
--- a/libs/nativewindow/include/android/hardware_buffer.h
+++ b/libs/nativewindow/include/android/hardware_buffer.h
@@ -334,8 +334,6 @@ typedef struct AHardwareBuffer AHardwareBuffer;
// clang-format on
-#if __ANDROID_API__ >= 26
-
/**
* Allocates a buffer that matches the passed AHardwareBuffer_Desc.
*
@@ -478,10 +476,6 @@ int AHardwareBuffer_recvHandleFromUnixSocket(int socketFd,
AHardwareBuffer* _Nullable* _Nonnull outBuffer)
__INTRODUCED_IN(26);
-#endif // __ANDROID_API__ >= 26
-
-#if __ANDROID_API__ >= 29
-
/**
* Lock a potentially multi-planar AHardwareBuffer for direct CPU access.
*
@@ -551,9 +545,6 @@ int AHardwareBuffer_lockAndGetInfo(AHardwareBuffer* _Nonnull buffer, uint64_t us
int32_t* _Nonnull outBytesPerPixel,
int32_t* _Nonnull outBytesPerStride) __INTRODUCED_IN(29);
-#endif // __ANDROID_API__ >= 29
-
-#if __ANDROID_API__ >= 31
/**
* Get the system wide unique id for an AHardwareBuffer.
@@ -566,8 +557,6 @@ int AHardwareBuffer_lockAndGetInfo(AHardwareBuffer* _Nonnull buffer, uint64_t us
int AHardwareBuffer_getId(const AHardwareBuffer* _Nonnull buffer, uint64_t* _Nonnull outId)
__INTRODUCED_IN(31);
-#endif // __ANDROID_API__ >= 31
-
__END_DECLS
#endif // ANDROID_HARDWARE_BUFFER_H
diff --git a/libs/nativewindow/include/android/native_window.h b/libs/nativewindow/include/android/native_window.h
index deea59b9fb..285f2fb7fe 100644
--- a/libs/nativewindow/include/android/native_window.h
+++ b/libs/nativewindow/include/android/native_window.h
@@ -186,8 +186,6 @@ int32_t ANativeWindow_lock(ANativeWindow* window, ANativeWindow_Buffer* outBuffe
*/
int32_t ANativeWindow_unlockAndPost(ANativeWindow* window);
-#if __ANDROID_API__ >= 26
-
/**
* Set a transform that will be applied to future buffers posted to the window.
*
@@ -198,10 +196,6 @@ int32_t ANativeWindow_unlockAndPost(ANativeWindow* window);
*/
int32_t ANativeWindow_setBuffersTransform(ANativeWindow* window, int32_t transform) __INTRODUCED_IN(26);
-#endif // __ANDROID_API__ >= 26
-
-#if __ANDROID_API__ >= 28
-
/**
* All buffers queued after this call will be associated with the dataSpace
* parameter specified.
@@ -230,10 +224,6 @@ int32_t ANativeWindow_setBuffersDataSpace(ANativeWindow* window, int32_t dataSpa
*/
int32_t ANativeWindow_getBuffersDataSpace(ANativeWindow* window) __INTRODUCED_IN(28);
-#endif // __ANDROID_API__ >= 28
-
-#if __ANDROID_API__ >= 30
-
/** Compatibility value for ANativeWindow_setFrameRate. */
enum ANativeWindow_FrameRateCompatibility {
/**
@@ -275,11 +265,7 @@ int32_t ANativeWindow_setFrameRate(ANativeWindow* window, float frameRate, int8_
*
* Available since API level 30.
*/
-void ANativeWindow_tryAllocateBuffers(ANativeWindow* window);
-
-#endif // __ANDROID_API__ >= 30
-
-#if __ANDROID_API__ >= 31
+void ANativeWindow_tryAllocateBuffers(ANativeWindow* window) __INTRODUCED_IN(30);
/**
* Sets the intended frame rate for this window.
@@ -322,8 +308,6 @@ void ANativeWindow_tryAllocateBuffers(ANativeWindow* window);
int32_t ANativeWindow_setFrameRateWithSeamlessness(ANativeWindow* window, float frameRate,
int8_t compatibility, bool shouldBeSeamless) __INTRODUCED_IN(31);
-#endif // __ANDROID_API__ >= 31
-
#ifdef __cplusplus
};
#endif
--
cgit v1.2.3-59-g8ed1b
From 7fed43d17aa7c6d8ff4d7a179d53ee7dc9f26d89 Mon Sep 17 00:00:00 2001
From: gfan
Date: Tue, 6 Apr 2021 18:50:06 -0700
Subject: Fix ndk native reference documentation link errors/warnings
Trivial changes, no functionality impact.
Bug: 183002717
Test: build ndk with 'm ndk' works
Change-Id: I1ee646f28500ad5769abdddd4e9780a1915fd528
---
include/android/bitmap.h | 1 +
include/android/choreographer.h | 5 +++++
include/android/font.h | 6 +++---
include/android/font_matcher.h | 14 +++++++-------
libs/nativewindow/include/android/native_window.h | 5 +++++
5 files changed, 21 insertions(+), 10 deletions(-)
(limited to 'include/android')
diff --git a/include/android/bitmap.h b/include/android/bitmap.h
index a70dffd756..6704a1ddf2 100644
--- a/include/android/bitmap.h
+++ b/include/android/bitmap.h
@@ -241,6 +241,7 @@ typedef struct AHardwareBuffer AHardwareBuffer;
*
* Available since API level 30.
*
+ * @param env Handle to the JNI environment pointer.
* @param bitmap Handle to an android.graphics.Bitmap.
* @param outBuffer On success, is set to a pointer to the
* {@link AHardwareBuffer} associated with bitmap. This acquires
diff --git a/include/android/choreographer.h b/include/android/choreographer.h
index cc5420e239..b743f491e4 100644
--- a/include/android/choreographer.h
+++ b/include/android/choreographer.h
@@ -32,6 +32,11 @@
__BEGIN_DECLS
struct AChoreographer;
+/**
+ * Opaque type that provides access to an AChoreographer object.
+ *
+ * A pointer can be obtained using {@link AChoreographer_getInstance()}.
+ */
typedef struct AChoreographer AChoreographer;
/**
diff --git a/include/android/font.h b/include/android/font.h
index a172618829..8a3a474f25 100644
--- a/include/android/font.h
+++ b/include/android/font.h
@@ -189,7 +189,7 @@ const char* _Nonnull AFont_getFontFilePath(const AFont* _Nonnull font) __INTRODU
* Available since API level 29.
*
* \param font a font object. Passing NULL is not allowed.
- * \return a positive integer less than or equal to {@link ASYSTEM_FONT_MAX_WEIGHT} is returned.
+ * \return a positive integer less than or equal to {@link AFONT_WEIGHT_MAX} is returned.
*/
uint16_t AFont_getWeight(const AFont* _Nonnull font) __INTRODUCED_IN(29);
@@ -241,7 +241,7 @@ size_t AFont_getCollectionIndex(const AFont* _Nonnull font) __INTRODUCED_IN(29);
* In this case, AFont_getAxisCount returns 2 and AFont_getAxisTag
* and AFont_getAxisValue will return following values.
* \code{.cpp}
- * AFont* font = AFontIterator_next(ite);
+ * AFont* font = ASystemFontIterator_next(ite);
*
* // Returns the number of axes
* AFont_getAxisCount(font); // Returns 2
@@ -289,7 +289,7 @@ uint32_t AFont_getAxisTag(const AFont* _Nonnull font, uint32_t axisIndex)
*
* \param font a font object. Passing NULL is not allowed.
* \param axisIndex an index to the font variation settings. Passing value larger than or
- * equal to {@link ASYstemFont_getAxisCount} is not allwed.
+ * equal to {@link AFont_getAxisCount} is not allowed.
* \return a float value for the given font variation setting.
*/
float AFont_getAxisValue(const AFont* _Nonnull font, uint32_t axisIndex)
diff --git a/include/android/font_matcher.h b/include/android/font_matcher.h
index 49e478c2f3..4417422687 100644
--- a/include/android/font_matcher.h
+++ b/include/android/font_matcher.h
@@ -36,7 +36,7 @@
* // Simple font query for the ASCII character.
* std::vector text = { 'A' };
* AFontMatcher* matcher = AFontMatcher_create("sans-serif");
- * ASystemFont* font = AFontMatcher_match(text.data(), text.length(), &runLength);
+ * AFont* font = AFontMatcher_match(text.data(), text.length(), &runLength);
* // runLength will be 1 and the font will points a valid font file.
* AFontMatcher_destroy(matcher);
*
@@ -44,17 +44,17 @@
* std::vector text = { 0x9AA8 };
* AFontMatcher* matcher = AFontMatcher_create("sans-serif");
* AFontMatcher_setLocales(matcher, "zh-CN,ja-JP");
- * ASystemFont* font = AFontMatcher_match(text.data(), text.length(), &runLength);
+ * AFont* font = AFontMatcher_match(text.data(), text.length(), &runLength);
* // runLength will be 1 and the font will points a Simplified Chinese font.
* AFontMatcher_setLocales(matcher, "ja-JP,zh-CN");
- * ASystemFont* font = AFontMatcher_match(text.data(), text.length(), &runLength);
+ * AFont* font = AFontMatcher_match(text.data(), text.length(), &runLength);
* // runLength will be 1 and the font will points a Japanese font.
* AFontMatcher_destroy(matcher);
*
* // Querying font for text/color emoji
* std::vector text = { 0xD83D, 0xDC68, 0x200D, 0x2764, 0xFE0F, 0x200D, 0xD83D, 0xDC68 };
* AFontMatcher* matcher = AFontMatcher_create("sans-serif");
- * ASystemFont* font = AFontMatcher_match(text.data(), text.length(), &runLength);
+ * AFont* font = AFontMatcher_match(text.data(), text.length(), &runLength);
* // runLength will be 8 and the font will points a color emoji font.
* AFontMatcher_destroy(matcher);
*
@@ -62,7 +62,7 @@
* // 0x05D0 is a Hebrew character and 0x0E01 is a Thai character.
* std::vector text = { 0x05D0, 0x0E01 };
* AFontMatcher* matcher = AFontMatcher_create("sans-serif");
- * ASystemFont* font = AFontMatcher_match(text.data(), text.length(), &runLength);
+ * AFont* font = AFontMatcher_match(text.data(), text.length(), &runLength);
* // runLength will be 1 and the font will points a Hebrew font.
* AFontMatcher_destroy(matcher);
* \endcode
@@ -146,7 +146,7 @@ void AFontMatcher_destroy(AFontMatcher* _Nonnull matcher) __INTRODUCED_IN(29);
/**
* Set font style to matcher.
*
- * If this function is not called, the matcher performs with {@link ASYSTEM_FONT_WEIGHT_NORMAL}
+ * If this function is not called, the matcher performs with {@link AFONT_WEIGHT_NORMAL}
* with non-italic style.
*
* Available since API level 29.
@@ -206,7 +206,7 @@ void AFontMatcher_setFamilyVariant(
* \param textLength a length of the given text buffer. This must not be zero.
* \param runLengthOut if not null, the font run length will be filled.
* \return a font to be used for given text and params. You need to release the returned font by
- * ASystemFont_close when it is no longer needed.
+ * AFont_close when it is no longer needed.
*/
AFont* _Nonnull AFontMatcher_match(
const AFontMatcher* _Nonnull matcher,
diff --git a/libs/nativewindow/include/android/native_window.h b/libs/nativewindow/include/android/native_window.h
index 50e9d53604..61b3f94aab 100644
--- a/libs/nativewindow/include/android/native_window.h
+++ b/libs/nativewindow/include/android/native_window.h
@@ -157,6 +157,7 @@ int32_t ANativeWindow_getFormat(ANativeWindow* window);
* For all of these parameters, if 0 is supplied then the window's base
* value will come back in force.
*
+ * \param window pointer to an ANativeWindow object.
* \param width width of the buffers in pixels.
* \param height height of the buffers in pixels.
* \param format one of the AHardwareBuffer_Format constants.
@@ -191,6 +192,7 @@ int32_t ANativeWindow_unlockAndPost(ANativeWindow* window);
*
* Available since API level 26.
*
+ * \param window pointer to an ANativeWindow object.
* \param transform combination of {@link ANativeWindowTransform} flags
* \return 0 for success, or -EINVAL if \p transform is invalid
*/
@@ -208,6 +210,7 @@ int32_t ANativeWindow_setBuffersTransform(ANativeWindow* window, int32_t transfo
*
* Available since API level 28.
*
+ * \param window pointer to an ANativeWindow object.
* \param dataSpace data space of all buffers queued after this call.
* \return 0 for success, -EINVAL if window is invalid or the dataspace is not
* supported.
@@ -306,6 +309,8 @@ enum ANativeWindow_ChangeFrameRateStrategy {
* valid refresh rate for this device's display - e.g., it's fine to pass 30fps
* to a device that can only run the display at 60fps.
*
+ * \param window pointer to an ANativeWindow object.
+ *
* \param compatibility The frame rate compatibility of this window. The
* compatibility value may influence the system's choice of display refresh
* rate. See the ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_* values for more info.
--
cgit v1.2.3-59-g8ed1b
From 7cdf8ef17636cdc5cc5fe41578951b4b1f23865c Mon Sep 17 00:00:00 2001
From: Antonio Kantek
Date: Tue, 13 Jul 2021 18:04:53 -0700
Subject: TouchEvent (1/n): Adding TouchModeEvent to InputChannel
This CL detaches the touch mode state update from focus update. It does
that by introducing a new internal event (TouchModeEvent). This CL also
adds this event to InputChannel and related processing logic to
InputPublisher and InputConsumer. InputDispatcher will process two
different events now: FocusEvent when gaining/losing focus and
TouchModeEvent when entering/leaving touch mode.
Test: atest libinput_tests
Bug: 193718270
Change-Id: Ie4e5b6e8e798f12d7203127b4559fa40d38788de
---
include/android/input.h | 3 ++
include/input/Input.h | 24 +++++++++++
include/input/InputTransport.h | 20 ++++++++++
libs/input/Input.cpp | 25 ++++++++++++
libs/input/InputTransport.cpp | 42 ++++++++++++++++++++
.../input/tests/InputPublisherAndConsumer_test.cpp | 46 ++++++++++++++++++++++
libs/input/tests/StructLayout_test.cpp | 5 +++
7 files changed, 165 insertions(+)
(limited to 'include/android')
diff --git a/include/android/input.h b/include/android/input.h
index bb98beb41a..f03facb929 100644
--- a/include/android/input.h
+++ b/include/android/input.h
@@ -169,6 +169,9 @@ enum {
/** Drag event */
AINPUT_EVENT_TYPE_DRAG = 5,
+
+ /** TouchMode event */
+ AINPUT_EVENT_TYPE_TOUCH_MODE = 6,
};
/**
diff --git a/include/input/Input.h b/include/input/Input.h
index b09ff482a8..a7d34e225b 100644
--- a/include/input/Input.h
+++ b/include/input/Input.h
@@ -883,6 +883,25 @@ protected:
float mX, mY;
};
+/*
+ * Touch mode events.
+ */
+class TouchModeEvent : public InputEvent {
+public:
+ virtual ~TouchModeEvent() {}
+
+ virtual int32_t getType() const override { return AINPUT_EVENT_TYPE_TOUCH_MODE; }
+
+ inline bool isInTouchMode() const { return mIsInTouchMode; }
+
+ void initialize(int32_t id, bool isInTouchMode);
+
+ void initialize(const TouchModeEvent& from);
+
+protected:
+ bool mIsInTouchMode;
+};
+
/**
* Base class for verified events.
* Do not create a VerifiedInputEvent explicitly.
@@ -947,6 +966,7 @@ public:
virtual FocusEvent* createFocusEvent() = 0;
virtual CaptureEvent* createCaptureEvent() = 0;
virtual DragEvent* createDragEvent() = 0;
+ virtual TouchModeEvent* createTouchModeEvent() = 0;
};
/*
@@ -963,6 +983,7 @@ public:
virtual FocusEvent* createFocusEvent() override { return &mFocusEvent; }
virtual CaptureEvent* createCaptureEvent() override { return &mCaptureEvent; }
virtual DragEvent* createDragEvent() override { return &mDragEvent; }
+ virtual TouchModeEvent* createTouchModeEvent() override { return &mTouchModeEvent; }
private:
KeyEvent mKeyEvent;
@@ -970,6 +991,7 @@ private:
FocusEvent mFocusEvent;
CaptureEvent mCaptureEvent;
DragEvent mDragEvent;
+ TouchModeEvent mTouchModeEvent;
};
/*
@@ -985,6 +1007,7 @@ public:
virtual FocusEvent* createFocusEvent() override;
virtual CaptureEvent* createCaptureEvent() override;
virtual DragEvent* createDragEvent() override;
+ virtual TouchModeEvent* createTouchModeEvent() override;
void recycle(InputEvent* event);
@@ -996,6 +1019,7 @@ private:
std::queue> mFocusEventPool;
std::queue> mCaptureEventPool;
std::queue> mDragEventPool;
+ std::queue> mTouchModeEventPool;
};
} // namespace android
diff --git a/include/input/InputTransport.h b/include/input/InputTransport.h
index 360dfbfd73..62cf67ea88 100644
--- a/include/input/InputTransport.h
+++ b/include/input/InputTransport.h
@@ -72,6 +72,7 @@ struct InputMessage {
CAPTURE,
DRAG,
TIMELINE,
+ TOUCH_MODE,
};
struct Header {
@@ -206,6 +207,15 @@ struct InputMessage {
inline size_t size() const { return sizeof(Timeline); }
} timeline;
+
+ struct TouchMode {
+ int32_t eventId;
+ // The following 2 fields take up 4 bytes total
+ bool isInTouchMode;
+ uint8_t empty[3];
+
+ inline size_t size() const { return sizeof(TouchMode); }
+ } touchMode;
} __attribute__((aligned(8))) body;
bool isValid(size_t actualSize) const;
@@ -387,6 +397,15 @@ public:
*/
status_t publishDragEvent(uint32_t seq, int32_t eventId, float x, float y, bool isExiting);
+ /* Publishes a touch mode event to the input channel.
+ *
+ * Returns OK on success.
+ * Returns WOULD_BLOCK if the channel is full.
+ * Returns DEAD_OBJECT if the channel's peer has been closed.
+ * Other errors probably indicate that the channel is broken.
+ */
+ status_t publishTouchModeEvent(uint32_t seq, int32_t eventId, bool isInTouchMode);
+
struct Finished {
uint32_t seq;
bool handled;
@@ -657,6 +676,7 @@ private:
static void initializeFocusEvent(FocusEvent* event, const InputMessage* msg);
static void initializeCaptureEvent(CaptureEvent* event, const InputMessage* msg);
static void initializeDragEvent(DragEvent* event, const InputMessage* msg);
+ static void initializeTouchModeEvent(TouchModeEvent* event, const InputMessage* msg);
static void addSample(MotionEvent* event, const InputMessage* msg);
static bool canAddSample(const Batch& batch, const InputMessage* msg);
static ssize_t findSampleNoLaterThan(const Batch& batch, nsecs_t time);
diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp
index 9390467f55..30d82b6051 100644
--- a/libs/input/Input.cpp
+++ b/libs/input/Input.cpp
@@ -163,6 +163,9 @@ const char* inputEventTypeToString(int32_t type) {
case AINPUT_EVENT_TYPE_DRAG: {
return "DRAG";
}
+ case AINPUT_EVENT_TYPE_TOUCH_MODE: {
+ return "TOUCH_MODE";
+ }
}
return "UNKNOWN";
}
@@ -882,6 +885,19 @@ void DragEvent::initialize(const DragEvent& from) {
mY = from.mY;
}
+// --- TouchModeEvent ---
+
+void TouchModeEvent::initialize(int32_t id, bool isInTouchMode) {
+ InputEvent::initialize(id, ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID, AINPUT_SOURCE_UNKNOWN,
+ ADISPLAY_ID_NONE, INVALID_HMAC);
+ mIsInTouchMode = isInTouchMode;
+}
+
+void TouchModeEvent::initialize(const TouchModeEvent& from) {
+ InputEvent::initialize(from);
+ mIsInTouchMode = from.mIsInTouchMode;
+}
+
// --- PooledInputEventFactory ---
PooledInputEventFactory::PooledInputEventFactory(size_t maxPoolSize) :
@@ -936,6 +952,15 @@ DragEvent* PooledInputEventFactory::createDragEvent() {
return event;
}
+TouchModeEvent* PooledInputEventFactory::createTouchModeEvent() {
+ if (mTouchModeEventPool.empty()) {
+ return new TouchModeEvent();
+ }
+ TouchModeEvent* event = mTouchModeEventPool.front().release();
+ mTouchModeEventPool.pop();
+ return event;
+}
+
void PooledInputEventFactory::recycle(InputEvent* event) {
switch (event->getType()) {
case AINPUT_EVENT_TYPE_KEY:
diff --git a/libs/input/InputTransport.cpp b/libs/input/InputTransport.cpp
index d6c1161509..595c9d9ec0 100644
--- a/libs/input/InputTransport.cpp
+++ b/libs/input/InputTransport.cpp
@@ -116,6 +116,7 @@ bool InputMessage::isValid(size_t actualSize) const {
case Type::FOCUS:
case Type::CAPTURE:
case Type::DRAG:
+ case Type::TOUCH_MODE:
return true;
case Type::TIMELINE: {
const nsecs_t gpuCompletedTime =
@@ -151,6 +152,8 @@ size_t InputMessage::size() const {
return sizeof(Header) + body.drag.size();
case Type::TIMELINE:
return sizeof(Header) + body.timeline.size();
+ case Type::TOUCH_MODE:
+ return sizeof(Header) + body.touchMode.size();
}
return sizeof(Header);
}
@@ -291,6 +294,10 @@ void InputMessage::getSanitizedCopy(InputMessage* msg) const {
msg->body.timeline.graphicsTimeline = body.timeline.graphicsTimeline;
break;
}
+ case InputMessage::Type::TOUCH_MODE: {
+ msg->body.touchMode.eventId = body.touchMode.eventId;
+ msg->body.touchMode.isInTouchMode = body.touchMode.isInTouchMode;
+ }
}
}
@@ -661,6 +668,22 @@ status_t InputPublisher::publishDragEvent(uint32_t seq, int32_t eventId, float x
return mChannel->sendMessage(&msg);
}
+status_t InputPublisher::publishTouchModeEvent(uint32_t seq, int32_t eventId, bool isInTouchMode) {
+ if (ATRACE_ENABLED()) {
+ std::string message =
+ StringPrintf("publishTouchModeEvent(inputChannel=%s, isInTouchMode=%s)",
+ mChannel->getName().c_str(), toString(isInTouchMode));
+ ATRACE_NAME(message.c_str());
+ }
+
+ InputMessage msg;
+ msg.header.type = InputMessage::Type::TOUCH_MODE;
+ msg.header.seq = seq;
+ msg.body.touchMode.eventId = eventId;
+ msg.body.touchMode.isInTouchMode = isInTouchMode;
+ return mChannel->sendMessage(&msg);
+}
+
android::base::Result InputPublisher::receiveConsumerResponse() {
if (DEBUG_TRANSPORT_ACTIONS) {
ALOGD("channel '%s' publisher ~ %s", mChannel->getName().c_str(), __func__);
@@ -862,6 +885,16 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, bool consum
*outEvent = dragEvent;
break;
}
+
+ case InputMessage::Type::TOUCH_MODE: {
+ TouchModeEvent* touchModeEvent = factory->createTouchModeEvent();
+ if (!touchModeEvent) return NO_MEMORY;
+
+ initializeTouchModeEvent(touchModeEvent, &mMsg);
+ *outSeq = mMsg.header.seq;
+ *outEvent = touchModeEvent;
+ break;
+ }
}
}
return OK;
@@ -1366,6 +1399,10 @@ void InputConsumer::initializeMotionEvent(MotionEvent* event, const InputMessage
pointerProperties, pointerCoords);
}
+void InputConsumer::initializeTouchModeEvent(TouchModeEvent* event, const InputMessage* msg) {
+ event->initialize(msg->body.touchMode.eventId, msg->body.touchMode.isInTouchMode);
+}
+
void InputConsumer::addSample(MotionEvent* event, const InputMessage* msg) {
uint32_t pointerCount = msg->body.motion.pointerCount;
PointerCoords pointerCoords[pointerCount];
@@ -1472,6 +1509,11 @@ std::string InputConsumer::dump() const {
presentTime);
break;
}
+ case InputMessage::Type::TOUCH_MODE: {
+ out += android::base::StringPrintf("isInTouchMode=%s",
+ toString(msg.body.touchMode.isInTouchMode));
+ break;
+ }
}
out += "\n";
}
diff --git a/libs/input/tests/InputPublisherAndConsumer_test.cpp b/libs/input/tests/InputPublisherAndConsumer_test.cpp
index d0c337c3a6..8e6f97c7f8 100644
--- a/libs/input/tests/InputPublisherAndConsumer_test.cpp
+++ b/libs/input/tests/InputPublisherAndConsumer_test.cpp
@@ -56,6 +56,7 @@ protected:
void PublishAndConsumeFocusEvent();
void PublishAndConsumeCaptureEvent();
void PublishAndConsumeDragEvent();
+ void PublishAndConsumeTouchModeEvent();
};
TEST_F(InputPublisherAndConsumerTest, GetChannel_ReturnsTheChannel) {
@@ -411,6 +412,46 @@ void InputPublisherAndConsumerTest::PublishAndConsumeDragEvent() {
<< "finished signal's consume time should be greater than publish time";
}
+void InputPublisherAndConsumerTest::PublishAndConsumeTouchModeEvent() {
+ status_t status;
+
+ constexpr uint32_t seq = 15;
+ int32_t eventId = InputEvent::nextId();
+ constexpr bool touchModeEnabled = true;
+ const nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC);
+
+ status = mPublisher->publishTouchModeEvent(seq, eventId, touchModeEnabled);
+ ASSERT_EQ(OK, status) << "publisher publishTouchModeEvent should return OK";
+
+ uint32_t consumeSeq;
+ InputEvent* event;
+ status = mConsumer->consume(&mEventFactory, true /*consumeBatches*/, -1, &consumeSeq, &event);
+ ASSERT_EQ(OK, status) << "consumer consume should return OK";
+
+ ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event";
+ ASSERT_EQ(AINPUT_EVENT_TYPE_TOUCH_MODE, event->getType())
+ << "consumer should have returned a touch mode event";
+
+ const TouchModeEvent& touchModeEvent = static_cast(*event);
+ EXPECT_EQ(seq, consumeSeq);
+ EXPECT_EQ(eventId, touchModeEvent.getId());
+ EXPECT_EQ(touchModeEnabled, touchModeEvent.isInTouchMode());
+
+ status = mConsumer->sendFinishedSignal(seq, true);
+ ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK";
+
+ Result result = mPublisher->receiveConsumerResponse();
+ ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
+ ASSERT_TRUE(std::holds_alternative(*result));
+ const InputPublisher::Finished& finish = std::get(*result);
+ ASSERT_EQ(seq, finish.seq)
+ << "receiveConsumerResponse should have returned the original sequence number";
+ ASSERT_TRUE(finish.handled)
+ << "receiveConsumerResponse should have set handled to consumer's reply";
+ ASSERT_GE(finish.consumeTime, publishTime)
+ << "finished signal's consume time should be greater than publish time";
+}
+
TEST_F(InputPublisherAndConsumerTest, SendTimeline) {
const int32_t inputEventId = 20;
std::array graphicsTimeline;
@@ -447,6 +488,10 @@ TEST_F(InputPublisherAndConsumerTest, PublishDragEvent_EndToEnd) {
ASSERT_NO_FATAL_FAILURE(PublishAndConsumeDragEvent());
}
+TEST_F(InputPublisherAndConsumerTest, PublishTouchModeEvent_EndToEnd) {
+ ASSERT_NO_FATAL_FAILURE(PublishAndConsumeTouchModeEvent());
+}
+
TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenSequenceNumberIsZero_ReturnsError) {
status_t status;
const size_t pointerCount = 1;
@@ -515,6 +560,7 @@ TEST_F(InputPublisherAndConsumerTest, PublishMultipleEvents_EndToEnd) {
ASSERT_NO_FATAL_FAILURE(PublishAndConsumeDragEvent());
ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent());
ASSERT_NO_FATAL_FAILURE(PublishAndConsumeKeyEvent());
+ ASSERT_NO_FATAL_FAILURE(PublishAndConsumeTouchModeEvent());
}
} // namespace android
diff --git a/libs/input/tests/StructLayout_test.cpp b/libs/input/tests/StructLayout_test.cpp
index 5861d55156..1a9ba5083c 100644
--- a/libs/input/tests/StructLayout_test.cpp
+++ b/libs/input/tests/StructLayout_test.cpp
@@ -102,6 +102,10 @@ void TestInputMessageAlignment() {
CHECK_OFFSET(InputMessage::Body::Timeline, eventId, 0);
CHECK_OFFSET(InputMessage::Body::Timeline, empty, 4);
CHECK_OFFSET(InputMessage::Body::Timeline, graphicsTimeline, 8);
+
+ CHECK_OFFSET(InputMessage::Body::TouchMode, eventId, 0);
+ CHECK_OFFSET(InputMessage::Body::TouchMode, isInTouchMode, 4);
+ CHECK_OFFSET(InputMessage::Body::TouchMode, empty, 5);
}
void TestHeaderSize() {
@@ -123,6 +127,7 @@ void TestBodySize() {
static_assert(sizeof(InputMessage::Body::Focus) == 8);
static_assert(sizeof(InputMessage::Body::Capture) == 8);
static_assert(sizeof(InputMessage::Body::Drag) == 16);
+ static_assert(sizeof(InputMessage::Body::TouchMode) == 8);
// Timeline
static_assert(GraphicsTimeline::SIZE == 2);
static_assert(sizeof(InputMessage::Body::Timeline) == 24);
--
cgit v1.2.3-59-g8ed1b
From 4879d8144abedcc77d9c42186b20ff0557bdca2a Mon Sep 17 00:00:00 2001
From: Rachel Lee
Date: Wed, 25 Aug 2021 11:50:11 -0700
Subject: Choreographer: add new NDK APIs for callback data.
Bug: 198191648
Bug: 168552873
Test: atest ChoreographerNativeTest
Change-Id: I2472acb7b724354b657fc89983fade7ced5eb7eb
---
include/android/choreographer.h | 58 ++++++
libs/nativedisplay/AChoreographer.cpp | 205 ++++++++++++++++++---
.../private/android/choreographer.h | 15 ++
libs/nativedisplay/libnativedisplay.map.txt | 14 ++
4 files changed, 264 insertions(+), 28 deletions(-)
(limited to 'include/android')
diff --git a/include/android/choreographer.h b/include/android/choreographer.h
index b743f491e4..0389e573a2 100644
--- a/include/android/choreographer.h
+++ b/include/android/choreographer.h
@@ -39,6 +39,12 @@ struct AChoreographer;
*/
typedef struct AChoreographer AChoreographer;
+struct AChoreographerFrameCallbackData;
+/**
+ * Opaque type that provides access to an AChoreographerFrameCallbackData object.
+ */
+typedef struct AChoreographerFrameCallbackData AChoreographerFrameCallbackData;
+
/**
* Prototype of the function that is called when a new frame is being rendered.
* It's passed the time that the frame is being rendered as nanoseconds in the
@@ -59,6 +65,14 @@ typedef void (*AChoreographer_frameCallback)(long frameTimeNanos, void* data);
*/
typedef void (*AChoreographer_frameCallback64)(int64_t frameTimeNanos, void* data);
+/**
+ * Prototype of the function that is called when a new frame is being rendered.
+ * It's passed the frame data that should not outlive the callback, as well as the data pointer
+ * provided by the application that registered a callback.
+ */
+typedef void (*AChoreographer_extendedFrameCallback)(
+ const AChoreographerFrameCallbackData* callbackData, void* data);
+
/**
* Prototype of the function that is called when the display refresh rate
* changes. It's passed the new vsync period in nanoseconds, as well as the data
@@ -110,6 +124,14 @@ void AChoreographer_postFrameCallbackDelayed64(AChoreographer* choreographer,
AChoreographer_frameCallback64 callback, void* data,
uint32_t delayMillis) __INTRODUCED_IN(29);
+/**
+ * Posts a callback to run on the next frame. The data pointer provided will
+ * be passed to the callback function when it's called.
+ */
+void AChoreographer_postExtendedFrameCallback(AChoreographer* choreographer,
+ AChoreographer_extendedFrameCallback callback, void* data)
+ __INTRODUCED_IN(33);
+
/**
* Registers a callback to be run when the display refresh rate changes. The
* data pointer provided will be passed to the callback function when it's
@@ -160,6 +182,42 @@ void AChoreographer_unregisterRefreshRateCallback(AChoreographer* choreographer,
AChoreographer_refreshRateCallback, void* data)
__INTRODUCED_IN(30);
+/**
+ * The time in nanoseconds when the frame started being rendered.
+ */
+int64_t AChoreographerFrameCallbackData_getFrameTimeNanos(
+ const AChoreographerFrameCallbackData* data) __INTRODUCED_IN(33);
+
+/**
+ * The number of possible frame timelines.
+ */
+size_t AChoreographerFrameCallbackData_getFrameTimelinesLength(
+ const AChoreographerFrameCallbackData* data) __INTRODUCED_IN(33);
+
+/**
+ * Get index of the platform-preferred FrameTimeline.
+ */
+size_t AChoreographerFrameCallbackData_getPreferredFrameTimelineIndex(
+ const AChoreographerFrameCallbackData* data) __INTRODUCED_IN(33);
+
+/**
+ * The vsync ID token used to map Choreographer data.
+ */
+int64_t AChoreographerFrameCallbackData_getFrameTimelineVsyncId(
+ const AChoreographerFrameCallbackData* data, size_t index) __INTRODUCED_IN(33);
+
+/**
+ * The time in nanoseconds which the frame at given index is expected to be presented.
+ */
+int64_t AChoreographerFrameCallbackData_getFrameTimelineExpectedPresentTime(
+ const AChoreographerFrameCallbackData* data, size_t index) __INTRODUCED_IN(33);
+
+/**
+ * The time in nanoseconds which the frame at given index needs to be ready by.
+ */
+int64_t AChoreographerFrameCallbackData_getFrameTimelineDeadline(
+ const AChoreographerFrameCallbackData* data, size_t index) __INTRODUCED_IN(33);
+
__END_DECLS
#endif // ANDROID_CHOREOGRAPHER_H
diff --git a/libs/nativedisplay/AChoreographer.cpp b/libs/nativedisplay/AChoreographer.cpp
index ba71960751..4c4a34f7e2 100644
--- a/libs/nativedisplay/AChoreographer.cpp
+++ b/libs/nativedisplay/AChoreographer.cpp
@@ -77,6 +77,7 @@ namespace android {
struct FrameCallback {
AChoreographer_frameCallback callback;
AChoreographer_frameCallback64 callback64;
+ AChoreographer_extendedFrameCallback extendedCallback;
void* data;
nsecs_t dueTime;
@@ -95,6 +96,27 @@ struct RefreshRateCallback {
class Choreographer;
+/**
+ * Implementation of AChoreographerFrameCallbackData.
+ */
+struct ChoreographerFrameCallbackDataImpl {
+ struct FrameTimeline {
+ int64_t vsyncId{0};
+ int64_t expectedPresentTimeNanos{0};
+ int64_t deadlineNanos{0};
+ };
+
+ int64_t frameTimeNanos{0};
+
+ size_t frameTimelinesLength;
+
+ std::vector frameTimelines;
+
+ size_t preferredFrameTimelineIndex;
+
+ const Choreographer* choreographer;
+};
+
struct {
std::mutex lock;
std::vector ptrs GUARDED_BY(lock);
@@ -107,7 +129,9 @@ class Choreographer : public DisplayEventDispatcher, public MessageHandler {
public:
explicit Choreographer(const sp& looper) EXCLUDES(gChoreographers.lock);
void postFrameCallbackDelayed(AChoreographer_frameCallback cb,
- AChoreographer_frameCallback64 cb64, void* data, nsecs_t delay);
+ AChoreographer_frameCallback64 cb64,
+ AChoreographer_extendedFrameCallback extendedCallback, void* data,
+ nsecs_t delay);
void registerRefreshRateCallback(AChoreographer_refreshRateCallback cb, void* data)
EXCLUDES(gChoreographers.lock);
void unregisterRefreshRateCallback(AChoreographer_refreshRateCallback cb, void* data);
@@ -130,6 +154,7 @@ public:
int64_t getVsyncId() const;
int64_t getFrameDeadline() const;
int64_t getFrameInterval() const;
+ bool inCallback() const;
private:
Choreographer(const Choreographer&) = delete;
@@ -145,6 +170,8 @@ private:
void scheduleCallbacks();
+ ChoreographerFrameCallbackDataImpl createFrameCallbackData(nsecs_t timestamp) const;
+
std::mutex mLock;
// Protected by mLock
std::priority_queue mFrameCallbacks;
@@ -152,6 +179,7 @@ private:
nsecs_t mLatestVsyncPeriod = -1;
VsyncEventData mLastVsyncEventData;
+ bool mInCallback = false;
const sp mLooper;
const std::thread::id mThreadId;
@@ -211,10 +239,12 @@ Choreographer::~Choreographer() {
}
}
-void Choreographer::postFrameCallbackDelayed(
- AChoreographer_frameCallback cb, AChoreographer_frameCallback64 cb64, void* data, nsecs_t delay) {
+void Choreographer::postFrameCallbackDelayed(AChoreographer_frameCallback cb,
+ AChoreographer_frameCallback64 cb64,
+ AChoreographer_extendedFrameCallback extendedCallback,
+ void* data, nsecs_t delay) {
nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
- FrameCallback callback{cb, cb64, data, now + delay};
+ FrameCallback callback{cb, cb64, extendedCallback, data, now + delay};
{
std::lock_guard _l{mLock};
mFrameCallbacks.push(callback);
@@ -370,7 +400,15 @@ void Choreographer::dispatchVsync(nsecs_t timestamp, PhysicalDisplayId, uint32_t
}
mLastVsyncEventData = vsyncEventData;
for (const auto& cb : callbacks) {
- if (cb.callback64 != nullptr) {
+ if (cb.extendedCallback != nullptr) {
+ const ChoreographerFrameCallbackDataImpl frameCallbackData =
+ createFrameCallbackData(timestamp);
+ mInCallback = true;
+ cb.extendedCallback(reinterpret_cast(
+ &frameCallbackData),
+ cb.data);
+ mInCallback = false;
+ } else if (cb.callback64 != nullptr) {
cb.callback64(timestamp, cb.data);
} else if (cb.callback != nullptr) {
cb.callback(timestamp, cb.data);
@@ -379,8 +417,8 @@ void Choreographer::dispatchVsync(nsecs_t timestamp, PhysicalDisplayId, uint32_t
}
void Choreographer::dispatchHotplug(nsecs_t, PhysicalDisplayId displayId, bool connected) {
- ALOGV("choreographer %p ~ received hotplug event (displayId=%s, connected=%s), ignoring.",
- this, to_string(displayId).c_str(), toString(connected));
+ ALOGV("choreographer %p ~ received hotplug event (displayId=%s, connected=%s), ignoring.", this,
+ to_string(displayId).c_str(), toString(connected));
}
void Choreographer::dispatchModeChanged(nsecs_t, PhysicalDisplayId, int32_t, nsecs_t) {
@@ -399,15 +437,15 @@ void Choreographer::dispatchNullEvent(nsecs_t, PhysicalDisplayId) {
void Choreographer::handleMessage(const Message& message) {
switch (message.what) {
- case MSG_SCHEDULE_CALLBACKS:
- scheduleCallbacks();
- break;
- case MSG_SCHEDULE_VSYNC:
- scheduleVsync();
- break;
- case MSG_HANDLE_REFRESH_RATE_UPDATES:
- handleRefreshRateUpdates();
- break;
+ case MSG_SCHEDULE_CALLBACKS:
+ scheduleCallbacks();
+ break;
+ case MSG_SCHEDULE_VSYNC:
+ scheduleVsync();
+ break;
+ case MSG_HANDLE_REFRESH_RATE_UPDATES:
+ handleRefreshRateUpdates();
+ break;
}
}
@@ -423,6 +461,22 @@ int64_t Choreographer::getFrameInterval() const {
return mLastVsyncEventData.frameInterval;
}
+bool Choreographer::inCallback() const {
+ return mInCallback;
+}
+
+ChoreographerFrameCallbackDataImpl Choreographer::createFrameCallbackData(nsecs_t timestamp) const {
+ std::vector frameTimelines;
+ frameTimelines.push_back({.vsyncId = mLastVsyncEventData.id,
+ .expectedPresentTimeNanos = mLastVsyncEventData.expectedPresentTime,
+ .deadlineNanos = mLastVsyncEventData.deadlineTimestamp});
+ return {.frameTimeNanos = timestamp,
+ .frameTimelinesLength = 1,
+ .preferredFrameTimelineIndex = 0,
+ .frameTimelines = frameTimelines,
+ .choreographer = this};
+}
+
} // namespace android
using namespace android;
@@ -435,6 +489,12 @@ static inline const Choreographer* AChoreographer_to_Choreographer(
return reinterpret_cast(choreographer);
}
+static inline const ChoreographerFrameCallbackDataImpl*
+AChoreographerFrameCallbackData_to_ChoreographerFrameCallbackDataImpl(
+ const AChoreographerFrameCallbackData* data) {
+ return reinterpret_cast(data);
+}
+
// Glue for private C api
namespace android {
void AChoreographer_signalRefreshRateCallbacks(nsecs_t vsyncPeriod) EXCLUDES(gChoreographers.lock) {
@@ -487,6 +547,11 @@ void AChoreographer_routePostFrameCallbackDelayed64(AChoreographer* choreographe
void* data, uint32_t delayMillis) {
return AChoreographer_postFrameCallbackDelayed64(choreographer, callback, data, delayMillis);
}
+void AChoreographer_routePostExtendedFrameCallback(AChoreographer* choreographer,
+ AChoreographer_extendedFrameCallback callback,
+ void* data) {
+ return AChoreographer_postExtendedFrameCallback(choreographer, callback, data);
+}
void AChoreographer_routeRegisterRefreshRateCallback(AChoreographer* choreographer,
AChoreographer_refreshRateCallback callback,
void* data) {
@@ -497,6 +562,30 @@ void AChoreographer_routeUnregisterRefreshRateCallback(AChoreographer* choreogra
void* data) {
return AChoreographer_unregisterRefreshRateCallback(choreographer, callback, data);
}
+int64_t AChoreographerFrameCallbackData_routeGetFrameTimeNanos(
+ const AChoreographerFrameCallbackData* data) {
+ return AChoreographerFrameCallbackData_getFrameTimeNanos(data);
+}
+size_t AChoreographerFrameCallbackData_routeGetFrameTimelinesLength(
+ const AChoreographerFrameCallbackData* data) {
+ return AChoreographerFrameCallbackData_getFrameTimelinesLength(data);
+}
+size_t AChoreographerFrameCallbackData_routeGetPreferredFrameTimelineIndex(
+ const AChoreographerFrameCallbackData* data) {
+ return AChoreographerFrameCallbackData_getPreferredFrameTimelineIndex(data);
+}
+int64_t AChoreographerFrameCallbackData_routeGetFrameTimelineVsyncId(
+ const AChoreographerFrameCallbackData* data, size_t index) {
+ return AChoreographerFrameCallbackData_getFrameTimelineVsyncId(data, index);
+}
+int64_t AChoreographerFrameCallbackData_routeGetFrameTimelineExpectedPresentTime(
+ const AChoreographerFrameCallbackData* data, size_t index) {
+ return AChoreographerFrameCallbackData_getFrameTimelineExpectedPresentTime(data, index);
+}
+int64_t AChoreographerFrameCallbackData_routeGetFrameTimelineDeadline(
+ const AChoreographerFrameCallbackData* data, size_t index) {
+ return AChoreographerFrameCallbackData_getFrameTimelineDeadline(data, index);
+}
int64_t AChoreographer_getVsyncId(const AChoreographer* choreographer) {
return AChoreographer_to_Choreographer(choreographer)->getVsyncId();
@@ -523,24 +612,32 @@ AChoreographer* AChoreographer_getInstance() {
}
void AChoreographer_postFrameCallback(AChoreographer* choreographer,
- AChoreographer_frameCallback callback, void* data) {
- AChoreographer_to_Choreographer(choreographer)->postFrameCallbackDelayed(
- callback, nullptr, data, 0);
+ AChoreographer_frameCallback callback, void* data) {
+ AChoreographer_to_Choreographer(choreographer)
+ ->postFrameCallbackDelayed(callback, nullptr, nullptr, data, 0);
}
void AChoreographer_postFrameCallbackDelayed(AChoreographer* choreographer,
- AChoreographer_frameCallback callback, void* data, long delayMillis) {
- AChoreographer_to_Choreographer(choreographer)->postFrameCallbackDelayed(
- callback, nullptr, data, ms2ns(delayMillis));
+ AChoreographer_frameCallback callback, void* data,
+ long delayMillis) {
+ AChoreographer_to_Choreographer(choreographer)
+ ->postFrameCallbackDelayed(callback, nullptr, nullptr, data, ms2ns(delayMillis));
+}
+void AChoreographer_postExtendedFrameCallback(AChoreographer* choreographer,
+ AChoreographer_extendedFrameCallback callback,
+ void* data) {
+ AChoreographer_to_Choreographer(choreographer)
+ ->postFrameCallbackDelayed(nullptr, nullptr, callback, data, 0);
}
void AChoreographer_postFrameCallback64(AChoreographer* choreographer,
- AChoreographer_frameCallback64 callback, void* data) {
- AChoreographer_to_Choreographer(choreographer)->postFrameCallbackDelayed(
- nullptr, callback, data, 0);
+ AChoreographer_frameCallback64 callback, void* data) {
+ AChoreographer_to_Choreographer(choreographer)
+ ->postFrameCallbackDelayed(nullptr, callback, nullptr, data, 0);
}
void AChoreographer_postFrameCallbackDelayed64(AChoreographer* choreographer,
- AChoreographer_frameCallback64 callback, void* data, uint32_t delayMillis) {
- AChoreographer_to_Choreographer(choreographer)->postFrameCallbackDelayed(
- nullptr, callback, data, ms2ns(delayMillis));
+ AChoreographer_frameCallback64 callback, void* data,
+ uint32_t delayMillis) {
+ AChoreographer_to_Choreographer(choreographer)
+ ->postFrameCallbackDelayed(nullptr, callback, nullptr, data, ms2ns(delayMillis));
}
void AChoreographer_registerRefreshRateCallback(AChoreographer* choreographer,
AChoreographer_refreshRateCallback callback,
@@ -553,6 +650,58 @@ void AChoreographer_unregisterRefreshRateCallback(AChoreographer* choreographer,
AChoreographer_to_Choreographer(choreographer)->unregisterRefreshRateCallback(callback, data);
}
+int64_t AChoreographerFrameCallbackData_getFrameTimeNanos(
+ const AChoreographerFrameCallbackData* data) {
+ const ChoreographerFrameCallbackDataImpl* frameCallbackData =
+ AChoreographerFrameCallbackData_to_ChoreographerFrameCallbackDataImpl(data);
+ LOG_ALWAYS_FATAL_IF(!frameCallbackData->choreographer->inCallback(),
+ "Data is only valid in callback");
+ return frameCallbackData->frameTimeNanos;
+}
+size_t AChoreographerFrameCallbackData_getFrameTimelinesLength(
+ const AChoreographerFrameCallbackData* data) {
+ const ChoreographerFrameCallbackDataImpl* frameCallbackData =
+ AChoreographerFrameCallbackData_to_ChoreographerFrameCallbackDataImpl(data);
+ LOG_ALWAYS_FATAL_IF(!frameCallbackData->choreographer->inCallback(),
+ "Data is only valid in callback");
+ return frameCallbackData->frameTimelinesLength;
+}
+size_t AChoreographerFrameCallbackData_getPreferredFrameTimelineIndex(
+ const AChoreographerFrameCallbackData* data) {
+ const ChoreographerFrameCallbackDataImpl* frameCallbackData =
+ AChoreographerFrameCallbackData_to_ChoreographerFrameCallbackDataImpl(data);
+ LOG_ALWAYS_FATAL_IF(!frameCallbackData->choreographer->inCallback(),
+ "Data is only valid in callback");
+ return frameCallbackData->preferredFrameTimelineIndex;
+}
+int64_t AChoreographerFrameCallbackData_getFrameTimelineVsyncId(
+ const AChoreographerFrameCallbackData* data, size_t index) {
+ const ChoreographerFrameCallbackDataImpl* frameCallbackData =
+ AChoreographerFrameCallbackData_to_ChoreographerFrameCallbackDataImpl(data);
+ LOG_ALWAYS_FATAL_IF(!frameCallbackData->choreographer->inCallback(),
+ "Data is only valid in callback");
+ LOG_ALWAYS_FATAL_IF(index >= frameCallbackData->frameTimelinesLength, "Index out of bounds");
+ return frameCallbackData->frameTimelines[index].vsyncId;
+}
+int64_t AChoreographerFrameCallbackData_getFrameTimelineExpectedPresentTime(
+ const AChoreographerFrameCallbackData* data, size_t index) {
+ const ChoreographerFrameCallbackDataImpl* frameCallbackData =
+ AChoreographerFrameCallbackData_to_ChoreographerFrameCallbackDataImpl(data);
+ LOG_ALWAYS_FATAL_IF(!frameCallbackData->choreographer->inCallback(),
+ "Data is only valid in callback");
+ LOG_ALWAYS_FATAL_IF(index >= frameCallbackData->frameTimelinesLength, "Index out of bounds");
+ return frameCallbackData->frameTimelines[index].expectedPresentTimeNanos;
+}
+int64_t AChoreographerFrameCallbackData_getFrameTimelineDeadline(
+ const AChoreographerFrameCallbackData* data, size_t index) {
+ const ChoreographerFrameCallbackDataImpl* frameCallbackData =
+ AChoreographerFrameCallbackData_to_ChoreographerFrameCallbackDataImpl(data);
+ LOG_ALWAYS_FATAL_IF(!frameCallbackData->choreographer->inCallback(),
+ "Data is only valid in callback");
+ LOG_ALWAYS_FATAL_IF(index >= frameCallbackData->frameTimelinesLength, "Index out of bounds");
+ return frameCallbackData->frameTimelines[index].deadlineNanos;
+}
+
AChoreographer* AChoreographer_create() {
Choreographer* choreographer = new Choreographer(nullptr);
status_t result = choreographer->initialize();
diff --git a/libs/nativedisplay/include-private/private/android/choreographer.h b/libs/nativedisplay/include-private/private/android/choreographer.h
index 7d25ce8253..6e90853b51 100644
--- a/libs/nativedisplay/include-private/private/android/choreographer.h
+++ b/libs/nativedisplay/include-private/private/android/choreographer.h
@@ -63,11 +63,26 @@ void AChoreographer_routePostFrameCallback64(AChoreographer* choreographer,
void AChoreographer_routePostFrameCallbackDelayed64(AChoreographer* choreographer,
AChoreographer_frameCallback64 callback,
void* data, uint32_t delayMillis);
+void AChoreographer_routePostExtendedFrameCallback(AChoreographer* choreographer,
+ AChoreographer_extendedFrameCallback callback,
+ void* data);
void AChoreographer_routeRegisterRefreshRateCallback(AChoreographer* choreographer,
AChoreographer_refreshRateCallback callback,
void* data);
void AChoreographer_routeUnregisterRefreshRateCallback(AChoreographer* choreographer,
AChoreographer_refreshRateCallback callback,
void* data);
+int64_t AChoreographerFrameCallbackData_routeGetFrameTimeNanos(
+ const AChoreographerFrameCallbackData* data);
+size_t AChoreographerFrameCallbackData_routeGetFrameTimelinesLength(
+ const AChoreographerFrameCallbackData* data);
+size_t AChoreographerFrameCallbackData_routeGetPreferredFrameTimelineIndex(
+ const AChoreographerFrameCallbackData* data);
+int64_t AChoreographerFrameCallbackData_routeGetFrameTimelineVsyncId(
+ const AChoreographerFrameCallbackData* data, size_t index);
+int64_t AChoreographerFrameCallbackData_routeGetFrameTimelineExpectedPresentTime(
+ const AChoreographerFrameCallbackData* data, size_t index);
+int64_t AChoreographerFrameCallbackData_routeGetFrameTimelineDeadline(
+ const AChoreographerFrameCallbackData* data, size_t index);
} // namespace android
diff --git a/libs/nativedisplay/libnativedisplay.map.txt b/libs/nativedisplay/libnativedisplay.map.txt
index 9ed4915481..b4a70e871c 100644
--- a/libs/nativedisplay/libnativedisplay.map.txt
+++ b/libs/nativedisplay/libnativedisplay.map.txt
@@ -7,6 +7,13 @@ LIBNATIVEDISPLAY {
AChoreographer_postFrameCallbackDelayed64; # apex # introduced=30
AChoreographer_registerRefreshRateCallback; # apex # introduced=30
AChoreographer_unregisterRefreshRateCallback; # apex # introduced=30
+ AChoreographer_postExtendedFrameCallback; # apex # introduced=33
+ AChoreographerFrameCallbackData_getFrameTimeNanos; # apex # introduced=33
+ AChoreographerFrameCallbackData_getFrameTimelinesLength; # apex # introduced=33
+ AChoreographerFrameCallbackData_getPreferredFrameTimelineIndex; # apex # introduced=33
+ AChoreographerFrameCallbackData_getFrameTimelineVsyncId; # apex # introduced=33
+ AChoreographerFrameCallbackData_getFrameTimelineExpectedPresentTime; # apex # introduced=33
+ AChoreographerFrameCallbackData_getFrameTimelineDeadline; # apex # introduced=33
AChoreographer_create; # apex # introduced=30
AChoreographer_destroy; # apex # introduced=30
AChoreographer_getFd; # apex # introduced=30
@@ -28,6 +35,13 @@ LIBNATIVEDISPLAY_PLATFORM {
android::AChoreographer_routePostFrameCallbackDelayed64*;
android::AChoreographer_routeRegisterRefreshRateCallback*;
android::AChoreographer_routeUnregisterRefreshRateCallback*;
+ android::AChoreographer_routePostExtendedFrameCallback*;
+ android::AChoreographerFrameCallbackData_routeGetFrameTimeNanos*;
+ android::AChoreographerFrameCallbackData_routeGetFrameTimelinesLength*;
+ android::AChoreographerFrameCallbackData_routeGetPreferredFrameTimelineIndex*;
+ android::AChoreographerFrameCallbackData_routeGetFrameTimelineVsyncId*;
+ android::AChoreographerFrameCallbackData_routeGetFrameTimelineExpectedPresentTime*;
+ android::AChoreographerFrameCallbackData_routeGetFrameTimelineDeadline*;
android::AChoreographer_signalRefreshRateCallbacks*;
android::AChoreographer_getVsyncId*;
android::AChoreographer_getFrameDeadline*;
--
cgit v1.2.3-59-g8ed1b
From a64c272fa2fac03883ec858fcd5ceabcc6b0b1d1 Mon Sep 17 00:00:00 2001
From: Jim Blackler
Date: Wed, 1 Sep 2021 16:39:16 +0100
Subject: Give access to the native InputQueue to all native applications.
Bug: 116830907
Test: atest android.view.cts.InputQueueTest#testNativeInputQueue
Change-Id: Ia92de418fe3407d0fa074f9fcb45d8844acbdf59
---
include/android/input.h | 8 ++++++++
1 file changed, 8 insertions(+)
(limited to 'include/android')
diff --git a/include/android/input.h b/include/android/input.h
index 6d2c1b3015..27587ce483 100644
--- a/include/android/input.h
+++ b/include/android/input.h
@@ -1385,6 +1385,14 @@ int32_t AInputQueue_preDispatchEvent(AInputQueue* queue, AInputEvent* event);
*/
void AInputQueue_finishEvent(AInputQueue* queue, AInputEvent* event, int handled);
+/**
+ * Supplies the AInputQueue* object associated with the supplied Java InputQueue
+ * object.
+ *
+ * Available since API level 33.
+ */
+AInputQueue* AInputQueue_fromJava(jobject inputQueue) __INTRODUCED_IN(33);
+
#ifdef __cplusplus
}
#endif
--
cgit v1.2.3-59-g8ed1b
From 406c8abeff595432782740345abad06280d18032 Mon Sep 17 00:00:00 2001
From: Bo Liu
Date: Wed, 10 Nov 2021 19:20:40 -0500
Subject: Performance hint ndk APIs
Test: atest PerformanceHintNativeTestCases
Change-Id: I46644adc4e07f668dd82d261da0aabeeb5403e86
---
include/android/performance_hint.h | 164 +++++++++++++++++++++++++++++
include/private/performance_hint_private.h | 116 --------------------
2 files changed, 164 insertions(+), 116 deletions(-)
create mode 100644 include/android/performance_hint.h
(limited to 'include/android')
diff --git a/include/android/performance_hint.h b/include/android/performance_hint.h
new file mode 100644
index 0000000000..5fa47f64be
--- /dev/null
+++ b/include/android/performance_hint.h
@@ -0,0 +1,164 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_NATIVE_PERFORMANCE_HINT_H
+#define ANDROID_NATIVE_PERFORMANCE_HINT_H
+
+#include
+
+/******************************************************************
+ *
+ * IMPORTANT NOTICE:
+ *
+ * This file is part of Android's set of stable system headers
+ * exposed by the Android NDK (Native Development Kit).
+ *
+ * Third-party source AND binary code relies on the definitions
+ * here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES.
+ *
+ * - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES)
+ * - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS
+ * - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY
+ * - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES
+ */
+
+#include
+#include
+
+__BEGIN_DECLS
+
+struct APerformanceHintManager;
+struct APerformanceHintSession;
+
+/**
+ * An opaque type representing a handle to a performance hint manager.
+ * It must be released after use.
+ *
+ * To use:
+ * - Obtain the performance hint manager instance by calling
+ * {@link APerformanceHint_getManager} function.
+ * - Create an {@link APerformanceHintSession} with
+ * {@link APerformanceHint_createSession}.
+ * - Get the preferred update rate in nanoseconds with
+ * {@link APerformanceHint_getPreferredUpdateRateNanos}.
+ */
+typedef struct APerformanceHintManager APerformanceHintManager;
+
+/**
+ * An opaque type representing a handle to a performance hint session.
+ * A session can only be acquired from a {@link APerformanceHintManager}
+ * with {@link APerformanceHint_getPreferredUpdateRateNanos}. It must be
+ * freed with {@link APerformanceHint_closeSession} after use.
+ *
+ * A Session represents a group of threads with an inter-related workload such that hints for
+ * their performance should be considered as a unit. The threads in a given session should be
+ * long-life and not created or destroyed dynamically.
+ *
+ * Each session is expected to have a periodic workload with a target duration for each
+ * cycle. The cycle duration is likely greater than the target work duration to allow other
+ * parts of the pipeline to run within the available budget. For example, a renderer thread may
+ * work at 60hz in order to produce frames at the display's frame but have a target work
+ * duration of only 6ms.
+ *
+ * After each cycle of work, the client is expected to use
+ * {@link APerformanceHint_reportActualWorkDuration} to report the actual time taken to
+ * complete.
+ *
+ * To use:
+ * - Update a sessions target duration for each cycle of work
+ * with {@link APerformanceHint_updateTargetWorkDuration}.
+ * - Report the actual duration for the last cycle of work with
+ * {@link APerformanceHint_reportActualWorkDuration}.
+ * - Release the session instance with
+ * {@link APerformanceHint_closeSession}.
+ */
+typedef struct APerformanceHintSession APerformanceHintSession;
+
+/**
+ * Acquire an instance of the performance hint manager.
+ *
+ * @return manager instance on success, nullptr on failure.
+ */
+APerformanceHintManager* APerformanceHint_getManager() __INTRODUCED_IN(__ANDROID_API_T__);
+
+/**
+ * Creates a session for the given set of threads and sets their initial target work
+ * duration.
+ * @param manager The performance hint manager instance.
+ * @param threadIds The list of threads to be associated with this session. They must be part of
+ * this app's thread group.
+ * @param size the size of threadIds.
+ * @param initialTargetWorkDurationNanos The desired duration in nanoseconds for the new session.
+ * This must be positive.
+ * @return manager instance on success, nullptr on failure.
+ */
+APerformanceHintSession* APerformanceHint_createSession(
+ APerformanceHintManager* manager,
+ const int32_t* threadIds, size_t size,
+ int64_t initialTargetWorkDurationNanos) __INTRODUCED_IN(__ANDROID_API_T__);
+
+/**
+ * Get preferred update rate information for this device.
+ *
+ * @param manager The performance hint manager instance.
+ * @return the preferred update rate supported by device software.
+ */
+int64_t APerformanceHint_getPreferredUpdateRateNanos(
+ APerformanceHintManager* manager) __INTRODUCED_IN(__ANDROID_API_T__);
+
+/**
+ * Updates this session's target duration for each cycle of work.
+ *
+ * @param session The performance hint session instance to update.
+ * @param targetDurationNanos the new desired duration in nanoseconds. This must be positive.
+ * @return 0 on success
+ * EINVAL if targetDurationNanos is not positive.
+ * EPIPE if communication with the system service has failed.
+ */
+int APerformanceHint_updateTargetWorkDuration(
+ APerformanceHintSession* session,
+ int64_t targetDurationNanos) __INTRODUCED_IN(__ANDROID_API_T__);
+
+/**
+ * Reports the actual duration for the last cycle of work.
+ *
+ * The system will attempt to adjust the core placement of the threads within the thread
+ * group and/or the frequency of the core on which they are run to bring the actual duration
+ * close to the target duration.
+ *
+ * @param session The performance hint session instance to update.
+ * @param actualDurationNanos how long the thread group took to complete its last task in
+ * nanoseconds. This must be positive.
+ * @return 0 on success
+ * EINVAL if actualDurationNanos is not positive.
+ * EPIPE if communication with the system service has failed.
+ */
+int APerformanceHint_reportActualWorkDuration(
+ APerformanceHintSession* session,
+ int64_t actualDurationNanos) __INTRODUCED_IN(__ANDROID_API_T__);
+
+/**
+ * Release the performance hint manager pointer acquired via
+ * {@link APerformanceHint_createSession}.
+ *
+ * @param session The performance hint session instance to release.
+ */
+void APerformanceHint_closeSession(
+ APerformanceHintSession* session) __INTRODUCED_IN(__ANDROID_API_T__);
+
+__END_DECLS
+
+#endif // ANDROID_NATIVE_PERFORMANCE_HINT_H
diff --git a/include/private/performance_hint_private.h b/include/private/performance_hint_private.h
index 5832bf49bd..f27f5f150f 100644
--- a/include/private/performance_hint_private.h
+++ b/include/private/performance_hint_private.h
@@ -17,124 +17,8 @@
#ifndef ANDROID_PRIVATE_NATIVE_PERFORMANCE_HINT_PRIVATE_H
#define ANDROID_PRIVATE_NATIVE_PERFORMANCE_HINT_PRIVATE_H
-#include
-
__BEGIN_DECLS
-struct APerformanceHintManager;
-struct APerformanceHintSession;
-
-/**
- * An opaque type representing a handle to a performance hint manager.
- * It must be released after use.
- *
- * To use:
- * - Obtain the performance hint manager instance by calling
- * {@link APerformanceHint_getManager} function.
- * - Create an {@link APerformanceHintSession} with
- * {@link APerformanceHint_createSession}.
- * - Get the preferred update rate in nanoseconds with
- * {@link APerformanceHint_getPreferredUpdateRateNanos}.
- */
-typedef struct APerformanceHintManager APerformanceHintManager;
-
-/**
- * An opaque type representing a handle to a performance hint session.
- * A session can only be acquired from a {@link APerformanceHintManager}
- * with {@link APerformanceHint_getPreferredUpdateRateNanos}. It must be
- * freed with {@link APerformanceHint_closeSession} after use.
- *
- * A Session represents a group of threads with an inter-related workload such that hints for
- * their performance should be considered as a unit. The threads in a given session should be
- * long-life and not created or destroyed dynamically.
- *
- * Each session is expected to have a periodic workload with a target duration for each
- * cycle. The cycle duration is likely greater than the target work duration to allow other
- * parts of the pipeline to run within the available budget. For example, a renderer thread may
- * work at 60hz in order to produce frames at the display's frame but have a target work
- * duration of only 6ms.
- *
- * After each cycle of work, the client is expected to use
- * {@link APerformanceHint_reportActualWorkDuration} to report the actual time taken to
- * complete.
- *
- * To use:
- * - Update a sessions target duration for each cycle of work
- * with {@link APerformanceHint_updateTargetWorkDuration}.
- * - Report the actual duration for the last cycle of work with
- * {@link APerformanceHint_reportActualWorkDuration}.
- * - Release the session instance with
- * {@link APerformanceHint_closeSession}.
- */
-typedef struct APerformanceHintSession APerformanceHintSession;
-
-/**
- * Acquire an instance of the performance hint manager.
- *
- * @return manager instance on success, nullptr on failure.
- */
-APerformanceHintManager* APerformanceHint_getManager();
-
-/**
- * Creates a session for the given set of threads and sets their initial target work
- * duration.
- * @param manager The performance hint manager instance.
- * @param threadIds The list of threads to be associated with this session. They must be part of
- * this app's thread group.
- * @param size the size of threadIds.
- * @param initialTargetWorkDurationNanos The desired duration in nanoseconds for the new session.
- * This must be positive.
- * @return manager instance on success, nullptr on failure.
- */
-APerformanceHintSession* APerformanceHint_createSession(APerformanceHintManager* manager,
- const int32_t* threadIds, size_t size,
- int64_t initialTargetWorkDurationNanos);
-
-/**
- * Get preferred update rate information for this device.
- *
- * @param manager The performance hint manager instance.
- * @return the preferred update rate supported by device software.
- */
-int64_t APerformanceHint_getPreferredUpdateRateNanos(APerformanceHintManager* manager);
-
-/**
- * Updates this session's target duration for each cycle of work.
- *
- * @param session The performance hint session instance to update.
- * @param targetDurationNanos the new desired duration in nanoseconds. This must be positive.
- * @return 0 on success
- * EINVAL if targetDurationNanos is not positive.
- * EPIPE if communication with the system service has failed.
- */
-int APerformanceHint_updateTargetWorkDuration(APerformanceHintSession* session,
- int64_t targetDurationNanos);
-
-/**
- * Reports the actual duration for the last cycle of work.
- *
- * The system will attempt to adjust the core placement of the threads within the thread
- * group and/or the frequency of the core on which they are run to bring the actual duration
- * close to the target duration.
- *
- * @param session The performance hint session instance to update.
- * @param actualDurationNanos how long the thread group took to complete its last task in
- * nanoseconds. This must be positive.
- * @return 0 on success
- * EINVAL if actualDurationNanos is not positive.
- * EPIPE if communication with the system service has failed.
- */
-int APerformanceHint_reportActualWorkDuration(APerformanceHintSession* session,
- int64_t actualDurationNanos);
-
-/**
- * Release the performance hint manager pointer acquired via
- * {@link APerformanceHint_createSession}.
- *
- * @param session The performance hint session instance to release.
- */
-void APerformanceHint_closeSession(APerformanceHintSession* session);
-
/**
* For testing only.
*/
--
cgit v1.2.3-59-g8ed1b
From ed511efbdfac3408cb3ae237016f095fd64cebec Mon Sep 17 00:00:00 2001
From: Rachel Lee
Date: Mon, 11 Oct 2021 15:09:51 -0700
Subject: Add frame timeline method to ASurfaceControl NDK.
Bug: 198192003
Test: atest ASurfaceControlTest
perfetto trace
Change-Id: I04310bd9190cfc227ff5ba892c7187d3b8a20463
---
include/android/surface_control.h | 9 +++++++++
libs/gui/FrameTimelineInfo.cpp | 5 +++++
libs/gui/Surface.cpp | 3 ++-
libs/gui/include/gui/FrameTimelineInfo.h | 3 +++
libs/nativewindow/include/system/window.h | 9 +++++----
services/surfaceflinger/FrameTimeline/FrameTimeline.cpp | 3 ++-
services/surfaceflinger/Layer.cpp | 2 ++
7 files changed, 28 insertions(+), 6 deletions(-)
(limited to 'include/android')
diff --git a/include/android/surface_control.h b/include/android/surface_control.h
index 059bc41f9a..3a131045e8 100644
--- a/include/android/surface_control.h
+++ b/include/android/surface_control.h
@@ -595,6 +595,15 @@ void ASurfaceTransaction_setEnableBackPressure(ASurfaceTransaction* transaction,
bool enableBackPressure)
__INTRODUCED_IN(31);
+/**
+ * Sets the frame timeline to use.
+ *
+ * \param vsyncId The vsync ID received from AChoreographer, setting the frame's present target to
+ * the corresponding expected present time and deadline from the frame to be rendered.
+ */
+void ASurfaceTransaction_setFrameTimeline(ASurfaceTransaction* transaction,
+ int64_t vsyncId) __INTRODUCED_IN(33);
+
__END_DECLS
#endif // ANDROID_SURFACE_CONTROL_H
diff --git a/libs/gui/FrameTimelineInfo.cpp b/libs/gui/FrameTimelineInfo.cpp
index 9231a570fc..3800b88ab0 100644
--- a/libs/gui/FrameTimelineInfo.cpp
+++ b/libs/gui/FrameTimelineInfo.cpp
@@ -33,12 +33,14 @@ namespace android {
status_t FrameTimelineInfo::write(Parcel& output) const {
SAFE_PARCEL(output.writeInt64, vsyncId);
SAFE_PARCEL(output.writeInt32, inputEventId);
+ SAFE_PARCEL(output.writeInt64, startTimeNanos);
return NO_ERROR;
}
status_t FrameTimelineInfo::read(const Parcel& input) {
SAFE_PARCEL(input.readInt64, &vsyncId);
SAFE_PARCEL(input.readInt32, &inputEventId);
+ SAFE_PARCEL(input.readInt64, &startTimeNanos);
return NO_ERROR;
}
@@ -48,16 +50,19 @@ void FrameTimelineInfo::merge(const FrameTimelineInfo& other) {
if (other.vsyncId > vsyncId) {
vsyncId = other.vsyncId;
inputEventId = other.inputEventId;
+ startTimeNanos = other.startTimeNanos;
}
} else if (vsyncId == INVALID_VSYNC_ID) {
vsyncId = other.vsyncId;
inputEventId = other.inputEventId;
+ startTimeNanos = other.startTimeNanos;
}
}
void FrameTimelineInfo::clear() {
vsyncId = INVALID_VSYNC_ID;
inputEventId = IInputConstants::INVALID_INPUT_EVENT_ID;
+ startTimeNanos = 0;
}
}; // namespace android
diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp
index 353a91d062..20c41460d4 100644
--- a/libs/gui/Surface.cpp
+++ b/libs/gui/Surface.cpp
@@ -1846,9 +1846,10 @@ int Surface::dispatchSetFrameTimelineInfo(va_list args) {
ATRACE_CALL();
auto frameTimelineVsyncId = static_cast(va_arg(args, int64_t));
auto inputEventId = static_cast(va_arg(args, int32_t));
+ auto startTimeNanos = static_cast(va_arg(args, int64_t));
ALOGV("Surface::%s", __func__);
- return setFrameTimelineInfo({frameTimelineVsyncId, inputEventId});
+ return setFrameTimelineInfo({frameTimelineVsyncId, inputEventId, startTimeNanos});
}
bool Surface::transformToDisplayInverse() const {
diff --git a/libs/gui/include/gui/FrameTimelineInfo.h b/libs/gui/include/gui/FrameTimelineInfo.h
index a23c20248c..255ce568d2 100644
--- a/libs/gui/include/gui/FrameTimelineInfo.h
+++ b/libs/gui/include/gui/FrameTimelineInfo.h
@@ -36,6 +36,9 @@ struct FrameTimelineInfo {
// not directly vendor available.
int32_t inputEventId = 0;
+ // The current time in nanoseconds the application started to render the frame.
+ int64_t startTimeNanos = 0;
+
status_t write(Parcel& output) const;
status_t read(const Parcel& input);
diff --git a/libs/nativewindow/include/system/window.h b/libs/nativewindow/include/system/window.h
index 0bc2b5d312..a319769148 100644
--- a/libs/nativewindow/include/system/window.h
+++ b/libs/nativewindow/include/system/window.h
@@ -1025,10 +1025,11 @@ static inline int native_window_set_frame_rate(struct ANativeWindow* window, flo
}
static inline int native_window_set_frame_timeline_info(struct ANativeWindow* window,
- int64_t frameTimelineVsyncId,
- int32_t inputEventId) {
- return window->perform(window, NATIVE_WINDOW_SET_FRAME_TIMELINE_INFO,
- frameTimelineVsyncId, inputEventId);
+ int64_t frameTimelineVsyncId,
+ int32_t inputEventId,
+ int64_t startTimeNanos) {
+ return window->perform(window, NATIVE_WINDOW_SET_FRAME_TIMELINE_INFO, frameTimelineVsyncId,
+ inputEventId, startTimeNanos);
}
// ------------------------------------------------------------------------------------------------
diff --git a/services/surfaceflinger/FrameTimeline/FrameTimeline.cpp b/services/surfaceflinger/FrameTimeline/FrameTimeline.cpp
index 0c4e1120fc..86e96d769c 100644
--- a/services/surfaceflinger/FrameTimeline/FrameTimeline.cpp
+++ b/services/surfaceflinger/FrameTimeline/FrameTimeline.cpp
@@ -667,7 +667,8 @@ void SurfaceFrame::traceActuals(int64_t displayFrameToken) const {
packet->set_timestamp(
static_cast(endTime - kPredictionExpiredStartTimeDelta));
} else {
- packet->set_timestamp(static_cast(mPredictions.startTime));
+ packet->set_timestamp(static_cast(
+ mActuals.startTime == 0 ? mPredictions.startTime : mActuals.startTime));
}
auto* event = packet->set_frame_timeline_event();
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 495d585509..c3b2fa598f 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -1253,6 +1253,7 @@ std::shared_ptr Layer::createSurfaceFrameForTransac
getSequence(), mName,
mTransactionName,
/*isBuffer*/ false, getGameMode());
+ surfaceFrame->setActualStartTime(info.startTimeNanos);
// For Transactions, the post time is considered to be both queue and acquire fence time.
surfaceFrame->setActualQueueTime(postTime);
surfaceFrame->setAcquireFenceTime(postTime);
@@ -1270,6 +1271,7 @@ std::shared_ptr Layer::createSurfaceFrameForBuffer(
mFlinger->mFrameTimeline->createSurfaceFrameForToken(info, mOwnerPid, mOwnerUid,
getSequence(), mName, debugName,
/*isBuffer*/ true, getGameMode());
+ surfaceFrame->setActualStartTime(info.startTimeNanos);
// For buffers, acquire fence time will set during latch.
surfaceFrame->setActualQueueTime(queueTime);
const auto fps = mFlinger->mScheduler->getFrameRateOverride(getOwnerUid());
--
cgit v1.2.3-59-g8ed1b
From b1e1e3914c8be41c83d3f6e7c71e53dffcd43f16 Mon Sep 17 00:00:00 2001
From: Prabir Pradhan
Date: Thu, 16 Dec 2021 03:28:20 -0800
Subject: Pass JNIEnv explicitly into AInputQueue_fromJava
Instead of assuming a JNIEnv*, the method should have the env passed
into it, which is the standard practice for native APIs.
Bug: 210727635
Test: atest InputQueueTest
Change-Id: I94d168e9370aed2081912971b82c472e18c65f12
---
include/android/input.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'include/android')
diff --git a/include/android/input.h b/include/android/input.h
index 27587ce483..447f8fa842 100644
--- a/include/android/input.h
+++ b/include/android/input.h
@@ -1391,7 +1391,7 @@ void AInputQueue_finishEvent(AInputQueue* queue, AInputEvent* event, int handled
*
* Available since API level 33.
*/
-AInputQueue* AInputQueue_fromJava(jobject inputQueue) __INTRODUCED_IN(33);
+AInputQueue* AInputQueue_fromJava(JNIEnv* env, jobject inputQueue) __INTRODUCED_IN(33);
#ifdef __cplusplus
}
--
cgit v1.2.3-59-g8ed1b
From 9d43974f4d7110552d5ca39d0a8576b8c87fdb6f Mon Sep 17 00:00:00 2001
From: Prabir Pradhan
Date: Thu, 16 Dec 2021 03:32:30 -0800
Subject: Add lifecycle information to docs for AInputQueue_fromJava
Add documentation to AInputQueue_fromJava to make it explicit that the
returned native object is only valid as long as the java object has not
yet been disposed.
Test: None
Bug: 210727408
Change-Id: I20ec68afba0ec79477d57b8a110d55220b7c01ff
---
include/android/input.h | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
(limited to 'include/android')
diff --git a/include/android/input.h b/include/android/input.h
index 447f8fa842..fbd61b53f4 100644
--- a/include/android/input.h
+++ b/include/android/input.h
@@ -1386,8 +1386,11 @@ int32_t AInputQueue_preDispatchEvent(AInputQueue* queue, AInputEvent* event);
void AInputQueue_finishEvent(AInputQueue* queue, AInputEvent* event, int handled);
/**
- * Supplies the AInputQueue* object associated with the supplied Java InputQueue
- * object.
+ * Returns the AInputQueue* object associated with the supplied Java InputQueue
+ * object. The returned native object holds a weak reference to the Java object,
+ * and is only valid as long as the Java object has not yet been disposed. You
+ * should ensure that there is a strong reference to the Java object and that it
+ * has not been disposed before using the returned object.
*
* Available since API level 33.
*/
--
cgit v1.2.3-59-g8ed1b
From 573da3b0f1d4381c2be5544709ad0cbec88fb982 Mon Sep 17 00:00:00 2001
From: Brian Duddie
Date: Fri, 10 Dec 2021 14:34:07 -0800
Subject: Add NDK support for new head tracker sensor type
Bug: 210156629
Test: presubmit (definitions only)
Change-Id: Ie93f3a99a3215690ab585b2e248edf096712c8c0
---
include/android/sensor.h | 40 +++++++++++++++++++++++++++
libs/sensor/Sensor.cpp | 4 +++
services/sensorservice/SensorServiceUtils.cpp | 3 ++
3 files changed, 47 insertions(+)
(limited to 'include/android')
diff --git a/include/android/sensor.h b/include/android/sensor.h
index 9dc6983e50..45e8afc7de 100644
--- a/include/android/sensor.h
+++ b/include/android/sensor.h
@@ -256,6 +256,13 @@ enum {
* The hinge angle sensor value is returned in degrees.
*/
ASENSOR_TYPE_HINGE_ANGLE = 36,
+ /**
+ * {@link ASENSOR_TYPE_HEAD_TRACKER}
+ * reporting-mode: continuous
+ *
+ * Measures the orientation and rotational velocity of a user's head.
+ */
+ ASENSOR_TYPE_HEAD_TRACKER = 37,
};
/**
@@ -440,6 +447,38 @@ typedef struct AAdditionalInfoEvent {
};
} AAdditionalInfoEvent;
+typedef struct AHeadTrackerEvent {
+ /**
+ * The fields rx, ry, rz are an Euler vector (rotation vector, i.e. a vector
+ * whose direction indicates the axis of rotation and magnitude indicates
+ * the angle to rotate around that axis) representing the transform from
+ * the (arbitrary, possibly slowly drifting) reference frame to the
+ * head frame. Expressed in radians. Magnitude of the vector must be
+ * in the range [0, pi], while the value of individual axes are
+ * in the range [-pi, pi].
+ */
+ float rx;
+ float ry;
+ float rz;
+
+ /**
+ * The fields vx, vy, vz are an Euler vector (rotation vector) representing
+ * the angular velocity of the head (relative to itself), in radians per
+ * second. The direction of this vector indicates the axis of rotation, and
+ * the magnitude indicates the rate of rotation.
+ */
+ float vx;
+ float vy;
+ float vz;
+
+ /**
+ * This value changes each time the reference frame is suddenly and
+ * significantly changed, for example if an orientation filter algorithm
+ * used for determining the orientation has had its state reset.
+ */
+ int32_t discontinuity_count;
+} AHeadTrackerEvent;
+
/**
* Information that describes a sensor event, refer to
* SensorEvent for additional
@@ -476,6 +515,7 @@ typedef struct ASensorEvent {
AHeartRateEvent heart_rate;
ADynamicSensorEvent dynamic_sensor_meta;
AAdditionalInfoEvent additional_info;
+ AHeadTrackerEvent head_tracker;
};
union {
uint64_t data[8];
diff --git a/libs/sensor/Sensor.cpp b/libs/sensor/Sensor.cpp
index 0a49008584..e1560c0740 100644
--- a/libs/sensor/Sensor.cpp
+++ b/libs/sensor/Sensor.cpp
@@ -276,6 +276,10 @@ Sensor::Sensor(struct sensor_t const& hwSensor, const uuid_t& uuid, int halVersi
mStringType = SENSOR_STRING_TYPE_HINGE_ANGLE;
mFlags |= SENSOR_FLAG_ON_CHANGE_MODE;
break;
+ case SENSOR_TYPE_HEAD_TRACKER:
+ mStringType = SENSOR_STRING_TYPE_HEAD_TRACKER;
+ mFlags |= SENSOR_FLAG_CONTINUOUS_MODE;
+ break;
default:
// Only pipe the stringType, requiredPermission and flags for custom sensors.
if (halVersion > SENSORS_DEVICE_API_VERSION_1_0 && hwSensor.stringType) {
diff --git a/services/sensorservice/SensorServiceUtils.cpp b/services/sensorservice/SensorServiceUtils.cpp
index fdd56b364d..baa01c9ce3 100644
--- a/services/sensorservice/SensorServiceUtils.cpp
+++ b/services/sensorservice/SensorServiceUtils.cpp
@@ -58,6 +58,9 @@ size_t eventSizeBySensorType(int type) {
case SENSOR_TYPE_HINGE_ANGLE:
return 1;
+ case SENSOR_TYPE_HEAD_TRACKER:
+ return 7;
+
default:
return 3;
}
--
cgit v1.2.3-59-g8ed1b
From 2825fa2979c783b879e2fe251baf37a139607ac0 Mon Sep 17 00:00:00 2001
From: Rachel Lee
Date: Wed, 12 Jan 2022 17:35:16 -0800
Subject: Rename AChoreographer frame timeline methods.
Test: atest ChoreographerNativeTest
Bug: 214303753
Change-Id: Id7c6ddcf7e0d46fb0b6eff35e46b4f937b59a058
---
include/android/choreographer.h | 4 ++--
libs/nativedisplay/AChoreographer.cpp | 12 ++++++------
.../include-private/private/android/choreographer.h | 4 ++--
libs/nativedisplay/libnativedisplay.map.txt | 8 ++++----
4 files changed, 14 insertions(+), 14 deletions(-)
(limited to 'include/android')
diff --git a/include/android/choreographer.h b/include/android/choreographer.h
index 0389e573a2..6f579ca0af 100644
--- a/include/android/choreographer.h
+++ b/include/android/choreographer.h
@@ -209,13 +209,13 @@ int64_t AChoreographerFrameCallbackData_getFrameTimelineVsyncId(
/**
* The time in nanoseconds which the frame at given index is expected to be presented.
*/
-int64_t AChoreographerFrameCallbackData_getFrameTimelineExpectedPresentTime(
+int64_t AChoreographerFrameCallbackData_getFrameTimelineExpectedPresentTimeNanos(
const AChoreographerFrameCallbackData* data, size_t index) __INTRODUCED_IN(33);
/**
* The time in nanoseconds which the frame at given index needs to be ready by.
*/
-int64_t AChoreographerFrameCallbackData_getFrameTimelineDeadline(
+int64_t AChoreographerFrameCallbackData_getFrameTimelineDeadlineNanos(
const AChoreographerFrameCallbackData* data, size_t index) __INTRODUCED_IN(33);
__END_DECLS
diff --git a/libs/nativedisplay/AChoreographer.cpp b/libs/nativedisplay/AChoreographer.cpp
index fc9680babb..84daea09f0 100644
--- a/libs/nativedisplay/AChoreographer.cpp
+++ b/libs/nativedisplay/AChoreographer.cpp
@@ -556,13 +556,13 @@ int64_t AChoreographerFrameCallbackData_routeGetFrameTimelineVsyncId(
const AChoreographerFrameCallbackData* data, size_t index) {
return AChoreographerFrameCallbackData_getFrameTimelineVsyncId(data, index);
}
-int64_t AChoreographerFrameCallbackData_routeGetFrameTimelineExpectedPresentTime(
+int64_t AChoreographerFrameCallbackData_routeGetFrameTimelineExpectedPresentTimeNanos(
const AChoreographerFrameCallbackData* data, size_t index) {
- return AChoreographerFrameCallbackData_getFrameTimelineExpectedPresentTime(data, index);
+ return AChoreographerFrameCallbackData_getFrameTimelineExpectedPresentTimeNanos(data, index);
}
-int64_t AChoreographerFrameCallbackData_routeGetFrameTimelineDeadline(
+int64_t AChoreographerFrameCallbackData_routeGetFrameTimelineDeadlineNanos(
const AChoreographerFrameCallbackData* data, size_t index) {
- return AChoreographerFrameCallbackData_getFrameTimelineDeadline(data, index);
+ return AChoreographerFrameCallbackData_getFrameTimelineDeadlineNanos(data, index);
}
int64_t AChoreographer_getFrameInterval(const AChoreographer* choreographer) {
@@ -653,7 +653,7 @@ int64_t AChoreographerFrameCallbackData_getFrameTimelineVsyncId(
LOG_ALWAYS_FATAL_IF(index >= frameCallbackData->frameTimelines.size(), "Index out of bounds");
return frameCallbackData->frameTimelines[index].id;
}
-int64_t AChoreographerFrameCallbackData_getFrameTimelineExpectedPresentTime(
+int64_t AChoreographerFrameCallbackData_getFrameTimelineExpectedPresentTimeNanos(
const AChoreographerFrameCallbackData* data, size_t index) {
const ChoreographerFrameCallbackDataImpl* frameCallbackData =
AChoreographerFrameCallbackData_to_ChoreographerFrameCallbackDataImpl(data);
@@ -662,7 +662,7 @@ int64_t AChoreographerFrameCallbackData_getFrameTimelineExpectedPresentTime(
LOG_ALWAYS_FATAL_IF(index >= frameCallbackData->frameTimelines.size(), "Index out of bounds");
return frameCallbackData->frameTimelines[index].expectedPresentTime;
}
-int64_t AChoreographerFrameCallbackData_getFrameTimelineDeadline(
+int64_t AChoreographerFrameCallbackData_getFrameTimelineDeadlineNanos(
const AChoreographerFrameCallbackData* data, size_t index) {
const ChoreographerFrameCallbackDataImpl* frameCallbackData =
AChoreographerFrameCallbackData_to_ChoreographerFrameCallbackDataImpl(data);
diff --git a/libs/nativedisplay/include-private/private/android/choreographer.h b/libs/nativedisplay/include-private/private/android/choreographer.h
index 4aa7e69097..0a1fcbeb94 100644
--- a/libs/nativedisplay/include-private/private/android/choreographer.h
+++ b/libs/nativedisplay/include-private/private/android/choreographer.h
@@ -67,9 +67,9 @@ size_t AChoreographerFrameCallbackData_routeGetPreferredFrameTimelineIndex(
const AChoreographerFrameCallbackData* data);
int64_t AChoreographerFrameCallbackData_routeGetFrameTimelineVsyncId(
const AChoreographerFrameCallbackData* data, size_t index);
-int64_t AChoreographerFrameCallbackData_routeGetFrameTimelineExpectedPresentTime(
+int64_t AChoreographerFrameCallbackData_routeGetFrameTimelineExpectedPresentTimeNanos(
const AChoreographerFrameCallbackData* data, size_t index);
-int64_t AChoreographerFrameCallbackData_routeGetFrameTimelineDeadline(
+int64_t AChoreographerFrameCallbackData_routeGetFrameTimelineDeadlineNanos(
const AChoreographerFrameCallbackData* data, size_t index);
} // namespace android
diff --git a/libs/nativedisplay/libnativedisplay.map.txt b/libs/nativedisplay/libnativedisplay.map.txt
index 4dbfde83cd..b1b6498fe9 100644
--- a/libs/nativedisplay/libnativedisplay.map.txt
+++ b/libs/nativedisplay/libnativedisplay.map.txt
@@ -12,8 +12,8 @@ LIBNATIVEDISPLAY {
AChoreographerFrameCallbackData_getFrameTimelinesLength; # apex # introduced=33
AChoreographerFrameCallbackData_getPreferredFrameTimelineIndex; # apex # introduced=33
AChoreographerFrameCallbackData_getFrameTimelineVsyncId; # apex # introduced=33
- AChoreographerFrameCallbackData_getFrameTimelineExpectedPresentTime; # apex # introduced=33
- AChoreographerFrameCallbackData_getFrameTimelineDeadline; # apex # introduced=33
+ AChoreographerFrameCallbackData_getFrameTimelineExpectedPresentTimeNanos; # apex # introduced=33
+ AChoreographerFrameCallbackData_getFrameTimelineDeadlineNanos; # apex # introduced=33
AChoreographer_create; # apex # introduced=30
AChoreographer_destroy; # apex # introduced=30
AChoreographer_getFd; # apex # introduced=30
@@ -40,8 +40,8 @@ LIBNATIVEDISPLAY_PLATFORM {
android::AChoreographerFrameCallbackData_routeGetFrameTimelinesLength*;
android::AChoreographerFrameCallbackData_routeGetPreferredFrameTimelineIndex*;
android::AChoreographerFrameCallbackData_routeGetFrameTimelineVsyncId*;
- android::AChoreographerFrameCallbackData_routeGetFrameTimelineExpectedPresentTime*;
- android::AChoreographerFrameCallbackData_routeGetFrameTimelineDeadline*;
+ android::AChoreographerFrameCallbackData_routeGetFrameTimelineExpectedPresentTimeNanos*;
+ android::AChoreographerFrameCallbackData_routeGetFrameTimelineDeadlineNanos*;
android::AChoreographer_signalRefreshRateCallbacks*;
android::AChoreographer_getFrameInterval*;
android::ADisplay_acquirePhysicalDisplays*;
--
cgit v1.2.3-59-g8ed1b
From 1fb2ddcb4cfb3c848b69ae2fe27b6c1b66ae792c Mon Sep 17 00:00:00 2001
From: Rachel Lee
Date: Wed, 12 Jan 2022 14:33:07 -0800
Subject: Improve ASurfaceTransaction_setFrameTimeline docs.
Also use a new typedef AVsyncId shared in AChoreographer and
ASurfaceControl.
Test: atest ASurfaceControlTest; atest ChoreographerNativeTest
Bug: 214063411
Change-Id: If24f144404038064de2ba72cca44572aca507e44
---
include/android/choreographer.h | 8 +++++++-
include/android/surface_control.h | 17 ++++++++++++++---
libs/nativedisplay/AChoreographer.cpp | 4 ++--
.../include-private/private/android/choreographer.h | 2 +-
4 files changed, 24 insertions(+), 7 deletions(-)
(limited to 'include/android')
diff --git a/include/android/choreographer.h b/include/android/choreographer.h
index 0389e573a2..889ecffd56 100644
--- a/include/android/choreographer.h
+++ b/include/android/choreographer.h
@@ -39,6 +39,12 @@ struct AChoreographer;
*/
typedef struct AChoreographer AChoreographer;
+
+/**
+ * The identifier of a frame timeline.
+ */
+typedef int64_t AVsyncId;
+
struct AChoreographerFrameCallbackData;
/**
* Opaque type that provides access to an AChoreographerFrameCallbackData object.
@@ -203,7 +209,7 @@ size_t AChoreographerFrameCallbackData_getPreferredFrameTimelineIndex(
/**
* The vsync ID token used to map Choreographer data.
*/
-int64_t AChoreographerFrameCallbackData_getFrameTimelineVsyncId(
+AVsyncId AChoreographerFrameCallbackData_getFrameTimelineVsyncId(
const AChoreographerFrameCallbackData* data, size_t index) __INTRODUCED_IN(33);
/**
diff --git a/include/android/surface_control.h b/include/android/surface_control.h
index 3a131045e8..9a36ecb537 100644
--- a/include/android/surface_control.h
+++ b/include/android/surface_control.h
@@ -28,6 +28,7 @@
#include
+#include
#include
#include
#include
@@ -596,13 +597,23 @@ void ASurfaceTransaction_setEnableBackPressure(ASurfaceTransaction* transaction,
__INTRODUCED_IN(31);
/**
- * Sets the frame timeline to use.
+ * Sets the frame timeline to use in Surface Flinger.
+ *
+ * A frame timeline should be chosen based on what frame deadline the application
+ * can meet when rendering the frame and the application's desired present time.
+ * By setting a frame timeline, Surface Flinger tries to present the frame at the corresponding
+ * expected present time.
+ *
+ * To receive frame timelines, a callback must be posted to Choreographer using
+ * AChoreographer_postExtendedFrameCallback(). The \a vsnycId can then be extracted from the
+ * callback payload using AChoreographerFrameCallbackData_getFrameTimelineVsyncId().
*
* \param vsyncId The vsync ID received from AChoreographer, setting the frame's present target to
- * the corresponding expected present time and deadline from the frame to be rendered.
+ * the corresponding expected present time and deadline from the frame to be rendered. A stale or
+ * invalid value will be ignored.
*/
void ASurfaceTransaction_setFrameTimeline(ASurfaceTransaction* transaction,
- int64_t vsyncId) __INTRODUCED_IN(33);
+ AVsyncId vsyncId) __INTRODUCED_IN(33);
__END_DECLS
diff --git a/libs/nativedisplay/AChoreographer.cpp b/libs/nativedisplay/AChoreographer.cpp
index fc9680babb..17c1ccc7de 100644
--- a/libs/nativedisplay/AChoreographer.cpp
+++ b/libs/nativedisplay/AChoreographer.cpp
@@ -552,7 +552,7 @@ size_t AChoreographerFrameCallbackData_routeGetPreferredFrameTimelineIndex(
const AChoreographerFrameCallbackData* data) {
return AChoreographerFrameCallbackData_getPreferredFrameTimelineIndex(data);
}
-int64_t AChoreographerFrameCallbackData_routeGetFrameTimelineVsyncId(
+AVsyncId AChoreographerFrameCallbackData_routeGetFrameTimelineVsyncId(
const AChoreographerFrameCallbackData* data, size_t index) {
return AChoreographerFrameCallbackData_getFrameTimelineVsyncId(data, index);
}
@@ -644,7 +644,7 @@ size_t AChoreographerFrameCallbackData_getPreferredFrameTimelineIndex(
"Data is only valid in callback");
return frameCallbackData->preferredFrameTimelineIndex;
}
-int64_t AChoreographerFrameCallbackData_getFrameTimelineVsyncId(
+AVsyncId AChoreographerFrameCallbackData_getFrameTimelineVsyncId(
const AChoreographerFrameCallbackData* data, size_t index) {
const ChoreographerFrameCallbackDataImpl* frameCallbackData =
AChoreographerFrameCallbackData_to_ChoreographerFrameCallbackDataImpl(data);
diff --git a/libs/nativedisplay/include-private/private/android/choreographer.h b/libs/nativedisplay/include-private/private/android/choreographer.h
index 4aa7e69097..5069e7471c 100644
--- a/libs/nativedisplay/include-private/private/android/choreographer.h
+++ b/libs/nativedisplay/include-private/private/android/choreographer.h
@@ -65,7 +65,7 @@ size_t AChoreographerFrameCallbackData_routeGetFrameTimelinesLength(
const AChoreographerFrameCallbackData* data);
size_t AChoreographerFrameCallbackData_routeGetPreferredFrameTimelineIndex(
const AChoreographerFrameCallbackData* data);
-int64_t AChoreographerFrameCallbackData_routeGetFrameTimelineVsyncId(
+AVsyncId AChoreographerFrameCallbackData_routeGetFrameTimelineVsyncId(
const AChoreographerFrameCallbackData* data, size_t index);
int64_t AChoreographerFrameCallbackData_routeGetFrameTimelineExpectedPresentTime(
const AChoreographerFrameCallbackData* data, size_t index);
--
cgit v1.2.3-59-g8ed1b
From f6ce3989e8c149173244e9f872beffee42fbf86f Mon Sep 17 00:00:00 2001
From: Alec Mouri
Date: Thu, 20 Jan 2022 14:31:35 -0800
Subject: Expose 1010102 config for bitmap
Bug: 200307898
Test: CtsGraphicsTestCases
Change-Id: I0201bbf51458aefd6f6c1c092f91cf7739cbc293
---
include/android/bitmap.h | 2 ++
1 file changed, 2 insertions(+)
(limited to 'include/android')
diff --git a/include/android/bitmap.h b/include/android/bitmap.h
index 6704a1ddf2..35f87f96ae 100644
--- a/include/android/bitmap.h
+++ b/include/android/bitmap.h
@@ -68,6 +68,8 @@ enum AndroidBitmapFormat {
ANDROID_BITMAP_FORMAT_A_8 = 8,
/** Each component is stored as a half float. **/
ANDROID_BITMAP_FORMAT_RGBA_F16 = 9,
+ /** Red: 10 bits, Green: 10 bits, Blue: 10 bits, Alpha: 2 bits. **/
+ ANDROID_BITMAP_FORMAT_RGBA_1010102 = 10,
};
/** Bitmap alpha format */
--
cgit v1.2.3-59-g8ed1b
From f8437960340854120486a547f0687b661629c3d9 Mon Sep 17 00:00:00 2001
From: Philip Junker
Date: Tue, 25 Jan 2022 21:20:19 +0100
Subject: Set keyboard type to maximum of all sub devices.
Bug: 216328642
Test: atest KeyboardLayoutChangeTest
Change-Id: Id01a7ea1c766dad0f5c6bb36f61d71a9eafa2d10
---
include/android/input.h | 1 +
include/input/InputDevice.h | 2 +-
libs/input/InputDevice.cpp | 7 +++++++
3 files changed, 9 insertions(+), 1 deletion(-)
(limited to 'include/android')
diff --git a/include/android/input.h b/include/android/input.h
index fbd61b53f4..e6ad943f55 100644
--- a/include/android/input.h
+++ b/include/android/input.h
@@ -877,6 +877,7 @@ enum {
* Keyboard types.
*
* Refer to the documentation on android.view.InputDevice for more details.
+ * Note: When adding a new keyboard type here InputDeviceInfo::setKeyboardType needs to be updated.
*/
enum {
/** none */
diff --git a/include/input/InputDevice.h b/include/input/InputDevice.h
index 22aae196c6..c4f03c9119 100644
--- a/include/input/InputDevice.h
+++ b/include/input/InputDevice.h
@@ -235,7 +235,7 @@ public:
void addBatteryInfo(const InputDeviceBatteryInfo& info);
void addLightInfo(const InputDeviceLightInfo& info);
- inline void setKeyboardType(int32_t keyboardType) { mKeyboardType = keyboardType; }
+ void setKeyboardType(int32_t keyboardType);
inline int32_t getKeyboardType() const { return mKeyboardType; }
inline void setKeyCharacterMap(const std::shared_ptr value) {
diff --git a/libs/input/InputDevice.cpp b/libs/input/InputDevice.cpp
index ac84627b3f..0bee1b6f2a 100644
--- a/libs/input/InputDevice.cpp
+++ b/libs/input/InputDevice.cpp
@@ -252,6 +252,13 @@ void InputDeviceInfo::addLightInfo(const InputDeviceLightInfo& info) {
mLights.insert_or_assign(info.id, info);
}
+void InputDeviceInfo::setKeyboardType(int32_t keyboardType) {
+ static_assert(AINPUT_KEYBOARD_TYPE_NONE < AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC);
+ static_assert(AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC < AINPUT_KEYBOARD_TYPE_ALPHABETIC);
+ // There can be multiple subdevices with different keyboard types, set it to the highest type
+ mKeyboardType = std::max(mKeyboardType, keyboardType);
+}
+
std::vector InputDeviceInfo::getSensors() {
std::vector infos;
infos.reserve(mSensors.size());
--
cgit v1.2.3-59-g8ed1b
From c0420b79bdfc7954a62fa10f3f29947e1130283c Mon Sep 17 00:00:00 2001
From: Eva Chen
Date: Fri, 9 Apr 2021 15:44:12 -0700
Subject: Add limited axes imu sensor types to sensor NDK.
Included sensors:
- SENSOR_TYPE_ACCELEROMETER_LIMITED_AXES
- SENSOR_TYPE_GYROSCOPE_LIMITED_AXES
- SENSOR_TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED
- SENSOR_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED
These changes will enable support for automotive style IMUs that have
more limited axes for accelerometers (x-axis and y-axis) and gyroscopes
(z-axis).
Bug: 187342209
Test: Presubmits
Change-Id: I7f8ecd4f3323c71c723a6415e573413cb464a0f1
---
include/android/sensor.h | 86 +++++++++++++++++++++++++++
libs/sensor/Sensor.cpp | 16 +++++
services/sensorservice/SensorServiceUtils.cpp | 6 ++
3 files changed, 108 insertions(+)
(limited to 'include/android')
diff --git a/include/android/sensor.h b/include/android/sensor.h
index 45e8afc7de..7e86d3fbb8 100644
--- a/include/android/sensor.h
+++ b/include/android/sensor.h
@@ -263,6 +263,44 @@ enum {
* Measures the orientation and rotational velocity of a user's head.
*/
ASENSOR_TYPE_HEAD_TRACKER = 37,
+ /**
+ * {@link ASENSOR_TYPE_ACCELEROMETER_LIMITED_AXES}
+ * reporting-mode: continuous
+ *
+ * The first three values are in SI units (m/s^2) and measure the acceleration of the device
+ * minus the force of gravity. The last three values indicate which acceleration axes are
+ * supported. A value of 1.0 means supported and a value of 0 means not supported.
+ */
+ ASENSOR_TYPE_ACCELEROMETER_LIMITED_AXES = 38,
+ /**
+ * {@link ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES}
+ * reporting-mode: continuous
+ *
+ * The first three values are in radians/second and measure the rate of rotation around the X,
+ * Y and Z axis. The last three values indicate which rotation axes are supported. A value of
+ * 1.0 means supported and a value of 0 means not supported.
+ */
+ ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES = 39,
+ /**
+ * {@link ASENSOR_TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED}
+ * reporting-mode: continuous
+ *
+ * The first three values are in SI units (m/s^2) and measure the acceleration of the device
+ * minus the force of gravity. The middle three values represent the estimated bias for each
+ * axis. The last three values indicate which acceleration axes are supported. A value of 1.0
+ * means supported and a value of 0 means not supported.
+ */
+ ASENSOR_TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED = 40,
+ /**
+ * {@link ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED}
+ * reporting-mode: continuous
+ *
+ * The first three values are in radians/second and measure the rate of rotation around the X,
+ * Y and Z axis. The middle three values represent the estimated drift around each axis in
+ * rad/s. The last three values indicate which rotation axes are supported. A value of 1.0 means
+ * supported and a value of 0 means not supported.
+ */
+ ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED = 41,
};
/**
@@ -479,6 +517,52 @@ typedef struct AHeadTrackerEvent {
int32_t discontinuity_count;
} AHeadTrackerEvent;
+typedef struct ALimitedAxesImuEvent {
+ union {
+ float calib[3];
+ struct {
+ float x;
+ float y;
+ float z;
+ };
+ };
+ union {
+ float supported[3];
+ struct {
+ float x_supported;
+ float y_supported;
+ float z_supported;
+ };
+ };
+} ALimitedAxesImuEvent;
+
+typedef struct ALimitedAxesImuUncalibratedEvent {
+ union {
+ float uncalib[3];
+ struct {
+ float x_uncalib;
+ float y_uncalib;
+ float z_uncalib;
+ };
+ };
+ union {
+ float bias[3];
+ struct {
+ float x_bias;
+ float y_bias;
+ float z_bias;
+ };
+ };
+ union {
+ float supported[3];
+ struct {
+ float x_supported;
+ float y_supported;
+ float z_supported;
+ };
+ };
+} ALimitedAxesImuUncalibratedEvent;
+
/**
* Information that describes a sensor event, refer to
* SensorEvent for additional
@@ -516,6 +600,8 @@ typedef struct ASensorEvent {
ADynamicSensorEvent dynamic_sensor_meta;
AAdditionalInfoEvent additional_info;
AHeadTrackerEvent head_tracker;
+ ALimitedAxesImuEvent limited_axes_imu;
+ ALimitedAxesImuUncalibratedEvent limited_axes_imu_uncalibrated;
};
union {
uint64_t data[8];
diff --git a/libs/sensor/Sensor.cpp b/libs/sensor/Sensor.cpp
index da88e8541a..5b4631a251 100644
--- a/libs/sensor/Sensor.cpp
+++ b/libs/sensor/Sensor.cpp
@@ -280,6 +280,22 @@ Sensor::Sensor(struct sensor_t const& hwSensor, const uuid_t& uuid, int halVersi
mStringType = SENSOR_STRING_TYPE_HEAD_TRACKER;
mFlags |= SENSOR_FLAG_CONTINUOUS_MODE;
break;
+ case SENSOR_TYPE_ACCELEROMETER_LIMITED_AXES:
+ mStringType = SENSOR_STRING_TYPE_ACCELEROMETER_LIMITED_AXES;
+ mFlags |= SENSOR_FLAG_CONTINUOUS_MODE;
+ break;
+ case SENSOR_TYPE_GYROSCOPE_LIMITED_AXES:
+ mStringType = SENSOR_STRING_TYPE_GYROSCOPE_LIMITED_AXES;
+ mFlags |= SENSOR_FLAG_CONTINUOUS_MODE;
+ break;
+ case SENSOR_TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED:
+ mStringType = SENSOR_STRING_TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED;
+ mFlags |= SENSOR_FLAG_CONTINUOUS_MODE;
+ break;
+ case SENSOR_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED:
+ mStringType = SENSOR_STRING_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED;
+ mFlags |= SENSOR_FLAG_CONTINUOUS_MODE;
+ break;
default:
// Only pipe the stringType, requiredPermission and flags for custom sensors.
if (halVersion > SENSORS_DEVICE_API_VERSION_1_0 && hwSensor.stringType) {
diff --git a/services/sensorservice/SensorServiceUtils.cpp b/services/sensorservice/SensorServiceUtils.cpp
index baa01c9ce3..c3043811f1 100644
--- a/services/sensorservice/SensorServiceUtils.cpp
+++ b/services/sensorservice/SensorServiceUtils.cpp
@@ -30,12 +30,18 @@ size_t eventSizeBySensorType(int type) {
case SENSOR_TYPE_POSE_6DOF:
return 16;
+ case SENSOR_TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED:
+ case SENSOR_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED:
+ return 9;
+
case SENSOR_TYPE_ROTATION_VECTOR:
case SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR:
return 5;
case SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED:
case SENSOR_TYPE_GYROSCOPE_UNCALIBRATED:
+ case SENSOR_TYPE_ACCELEROMETER_LIMITED_AXES:
+ case SENSOR_TYPE_GYROSCOPE_LIMITED_AXES:
return 6;
case SENSOR_TYPE_GAME_ROTATION_VECTOR:
--
cgit v1.2.3-59-g8ed1b
From 72c7104cab3a0e5bc886fab3acde0ba77fbabd49 Mon Sep 17 00:00:00 2001
From: Eva Chen
Date: Mon, 10 Jan 2022 21:07:51 -0800
Subject: Add TYPE_HEADING sensor type to sensor NDK.
Bug: 189983308
Test: Presubmits
Change-Id: I53bc59d6a1d03ab5e980920f0420ce0263cbc52c
---
include/android/sensor.h | 26 ++++++++++++++++++++++++++
libs/sensor/Sensor.cpp | 4 ++++
services/sensorservice/SensorServiceUtils.cpp | 3 +++
3 files changed, 33 insertions(+)
(limited to 'include/android')
diff --git a/include/android/sensor.h b/include/android/sensor.h
index 7e86d3fbb8..cf1ca02cb3 100644
--- a/include/android/sensor.h
+++ b/include/android/sensor.h
@@ -301,6 +301,14 @@ enum {
* supported and a value of 0 means not supported.
*/
ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED = 41,
+ /**
+ * {@link ASENSOR_TYPE_HEADING}
+ * reporting-mode: continuous
+ *
+ * A heading sensor measures the direction in which the device is pointing
+ * relative to true north in degrees.
+ */
+ ASENSOR_TYPE_HEADING = 42,
};
/**
@@ -563,6 +571,23 @@ typedef struct ALimitedAxesImuUncalibratedEvent {
};
} ALimitedAxesImuUncalibratedEvent;
+typedef struct AHeadingEvent {
+ /**
+ * The direction in which the device is pointing relative to true north in
+ * degrees. The value must be between 0.0 (inclusive) and 360.0 (exclusive),
+ * with 0 indicating north, 90 east, 180 south, and 270 west.
+ */
+ float heading;
+ /**
+ * Accuracy is defined at 68% confidence. In the case where the underlying
+ * distribution is assumed Gaussian normal, this would be considered one
+ * standard deviation. For example, if the heading returns 60 degrees, and
+ * accuracy returns 10 degrees, then there is a 68 percent probability of
+ * the true heading being between 50 degrees and 70 degrees.
+ */
+ float accuracy;
+} AHeadingEvent;
+
/**
* Information that describes a sensor event, refer to
* SensorEvent for additional
@@ -602,6 +627,7 @@ typedef struct ASensorEvent {
AHeadTrackerEvent head_tracker;
ALimitedAxesImuEvent limited_axes_imu;
ALimitedAxesImuUncalibratedEvent limited_axes_imu_uncalibrated;
+ AHeadingEvent heading;
};
union {
uint64_t data[8];
diff --git a/libs/sensor/Sensor.cpp b/libs/sensor/Sensor.cpp
index 5b4631a251..ec0ced8663 100644
--- a/libs/sensor/Sensor.cpp
+++ b/libs/sensor/Sensor.cpp
@@ -296,6 +296,10 @@ Sensor::Sensor(struct sensor_t const& hwSensor, const uuid_t& uuid, int halVersi
mStringType = SENSOR_STRING_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED;
mFlags |= SENSOR_FLAG_CONTINUOUS_MODE;
break;
+ case SENSOR_TYPE_HEADING:
+ mStringType = SENSOR_STRING_TYPE_HEADING;
+ mFlags |= SENSOR_FLAG_CONTINUOUS_MODE;
+ break;
default:
// Only pipe the stringType, requiredPermission and flags for custom sensors.
if (halVersion > SENSORS_DEVICE_API_VERSION_1_0 && hwSensor.stringType) {
diff --git a/services/sensorservice/SensorServiceUtils.cpp b/services/sensorservice/SensorServiceUtils.cpp
index c3043811f1..7dd23316b1 100644
--- a/services/sensorservice/SensorServiceUtils.cpp
+++ b/services/sensorservice/SensorServiceUtils.cpp
@@ -67,6 +67,9 @@ size_t eventSizeBySensorType(int type) {
case SENSOR_TYPE_HEAD_TRACKER:
return 7;
+ case SENSOR_TYPE_HEADING:
+ return 2;
+
default:
return 3;
}
--
cgit v1.2.3-59-g8ed1b
From d35a5741259e3b5fa6e8f196a1cd8230c7c9abbd Mon Sep 17 00:00:00 2001
From: Erik Staats
Date: Fri, 4 Feb 2022 06:37:58 -0800
Subject: Add ASensorManager_getDynamicSensorList.
Bug: 217890463
Test: Used uhid-sample to add a dynamic sensor and verified it can be
used with sensor_test.
Change-Id: Ida2ce53c3d94ed530ba4981d299fa4855c35e337
---
include/android/sensor.h | 27 +++++++++++++++++++++++-
libs/sensor/SensorManager.cpp | 33 ++++++++++++++++++++++++++++++
libs/sensor/include/sensor/SensorManager.h | 3 +++
3 files changed, 62 insertions(+), 1 deletion(-)
(limited to 'include/android')
diff --git a/include/android/sensor.h b/include/android/sensor.h
index 45e8afc7de..c5d50d25be 100644
--- a/include/android/sensor.h
+++ b/include/android/sensor.h
@@ -631,10 +631,35 @@ ASensorManager* ASensorManager_getInstance() __DEPRECATED_IN(26);
ASensorManager* ASensorManager_getInstanceForPackage(const char* packageName) __INTRODUCED_IN(26);
/**
- * Returns the list of available sensors.
+ * Returns the list of available sensors. The returned list is owned by the
+ * sensor manager and will not change between calls to this function.
+ *
+ * \param manager the {@link ASensorManager} instance obtained from
+ * {@link ASensorManager_getInstanceForPackage}.
+ * \param list the returned list of sensors.
+ * \return positive number of returned sensors or negative error code.
+ * BAD_VALUE: manager is NULL.
*/
int ASensorManager_getSensorList(ASensorManager* manager, ASensorList* list);
+/**
+ * Returns the list of available dynamic sensors. If there are no dynamic
+ * sensors available, returns nullptr in list.
+ *
+ * Each time this is called, the previously returned list is deallocated and
+ * must no longer be used.
+ *
+ * Available since API level 33.
+ *
+ * \param manager the {@link ASensorManager} instance obtained from
+ * {@link ASensorManager_getInstanceForPackage}.
+ * \param list the returned list of dynamic sensors.
+ * \return positive number of returned sensors or negative error code.
+ * BAD_VALUE: manager is NULL.
+ */
+ssize_t ASensorManager_getDynamicSensorList(
+ ASensorManager* manager, ASensorList* list) __INTRODUCED_IN(33);
+
/**
* Returns the default sensor for the given type, or NULL if no sensor
* of that type exists.
diff --git a/libs/sensor/SensorManager.cpp b/libs/sensor/SensorManager.cpp
index 62f4b4e3e2..0ba9704263 100644
--- a/libs/sensor/SensorManager.cpp
+++ b/libs/sensor/SensorManager.cpp
@@ -100,6 +100,7 @@ SensorManager::SensorManager(const String16& opPackageName)
SensorManager::~SensorManager() {
free(mSensorList);
+ free(mDynamicSensorList);
}
status_t SensorManager::waitForSensorService(sp *server) {
@@ -130,6 +131,9 @@ void SensorManager::sensorManagerDied() {
free(mSensorList);
mSensorList = nullptr;
mSensors.clear();
+ free(mDynamicSensorList);
+ mDynamicSensorList = nullptr;
+ mDynamicSensors.clear();
}
status_t SensorManager::assertStateLocked() {
@@ -197,6 +201,35 @@ ssize_t SensorManager::getDynamicSensorList(Vector & dynamicSensors) {
return static_cast(count);
}
+ssize_t SensorManager::getDynamicSensorList(Sensor const* const** list) {
+ Mutex::Autolock _l(mLock);
+ status_t err = assertStateLocked();
+ if (err < 0) {
+ return static_cast(err);
+ }
+
+ free(mDynamicSensorList);
+ mDynamicSensorList = nullptr;
+ mDynamicSensors = mSensorServer->getDynamicSensorList(mOpPackageName);
+ size_t dynamicCount = mDynamicSensors.size();
+ if (dynamicCount > 0) {
+ mDynamicSensorList = static_cast(
+ malloc(dynamicCount * sizeof(Sensor*)));
+ if (mDynamicSensorList == nullptr) {
+ ALOGE("Failed to allocate dynamic sensor list for %zu sensors.",
+ dynamicCount);
+ return static_cast(NO_MEMORY);
+ }
+
+ for (size_t i = 0; i < dynamicCount; i++) {
+ mDynamicSensorList[i] = mDynamicSensors.array() + i;
+ }
+ }
+
+ *list = mDynamicSensorList;
+ return static_cast(mDynamicSensors.size());
+}
+
Sensor const* SensorManager::getDefaultSensor(int type)
{
Mutex::Autolock _l(mLock);
diff --git a/libs/sensor/include/sensor/SensorManager.h b/libs/sensor/include/sensor/SensorManager.h
index 09ac7edf27..8d0a8a45d9 100644
--- a/libs/sensor/include/sensor/SensorManager.h
+++ b/libs/sensor/include/sensor/SensorManager.h
@@ -58,6 +58,7 @@ public:
ssize_t getSensorList(Sensor const* const** list);
ssize_t getDynamicSensorList(Vector& list);
+ ssize_t getDynamicSensorList(Sensor const* const** list);
Sensor const* getDefaultSensor(int type);
sp createEventQueue(
String8 packageName = String8(""), int mode = 0, String16 attributionTag = String16(""));
@@ -83,6 +84,8 @@ private:
sp mSensorServer;
Sensor const** mSensorList;
Vector mSensors;
+ Sensor const** mDynamicSensorList = nullptr;
+ Vector mDynamicSensors;
sp mDeathObserver;
const String16 mOpPackageName;
std::unordered_map> mDirectConnection;
--
cgit v1.2.3-59-g8ed1b
From 8576dd703e41f0d05a4f4635c675e1aedb77561a Mon Sep 17 00:00:00 2001
From: Vaibhav
Date: Fri, 11 Feb 2022 18:19:06 +0530
Subject: Add new NDK function definitions in input.h
This CL adds 2 new functions to get ActionButton and Classification from
a MotionEvent.
Test: atest android.view.cts.MotionEventTest
Bug: 213266814
Change-Id: Id264a5d110c6c65a7daae89194ab234f64832e13
---
include/android/input.h | 44 ++++++++++++++++++++++++++++++++++++++++++++
include/input/Input.h | 8 +++-----
2 files changed, 47 insertions(+), 5 deletions(-)
(limited to 'include/android')
diff --git a/include/android/input.h b/include/android/input.h
index e6ad943f55..fb5e204450 100644
--- a/include/android/input.h
+++ b/include/android/input.h
@@ -807,6 +807,33 @@ enum {
AMOTION_EVENT_TOOL_TYPE_PALM = 5,
};
+/**
+ * Constants that identify different gesture classification types.
+ */
+enum {
+ /**
+ * Classification constant: None.
+ *
+ * No additional information is available about the current motion event stream.
+ */
+ AMOTION_EVENT_CLASSIFICATION_NONE = 0,
+ /**
+ * Classification constant: Ambiguous gesture.
+ *
+ * The user's intent with respect to the current event stream is not yet determined.
+ * Gestural actions, such as scrolling, should be inhibited until the classification resolves
+ * to another value or the event stream ends.
+ */
+ AMOTION_EVENT_CLASSIFICATION_AMBIGUOUS_GESTURE = 1,
+ /**
+ * Classification constant: Deep press.
+ *
+ * The current event stream represents the user intentionally pressing harder on the screen.
+ * This classification type should be used to accelerate the long press behaviour.
+ */
+ AMOTION_EVENT_CLASSIFICATION_DEEP_PRESS = 2,
+};
+
/**
* Input source masks.
*
@@ -1326,6 +1353,23 @@ float AMotionEvent_getHistoricalOrientation(const AInputEvent* motion_event, siz
float AMotionEvent_getHistoricalAxisValue(const AInputEvent* motion_event,
int32_t axis, size_t pointer_index, size_t history_index);
+/**
+ * Get the action button for the motion event. Returns a valid action button when the
+ * event is associated with a button press or button release action. For other actions
+ * the return value is undefined.
+ */
+int32_t AMotionEvent_getActionButton(const AInputEvent* motion_event);
+
+/**
+ * Returns the classification for the current gesture.
+ * The classification may change as more events become available for the same gesture.
+ *
+ * @see #AMOTION_EVENT_CLASSIFICATION_NONE
+ * @see #AMOTION_EVENT_CLASSIFICATION_AMBIGUOUS_GESTURE
+ * @see #AMOTION_EVENT_CLASSIFICATION_DEEP_PRESS
+*/
+int32_t AMotionEvent_getClassification(const AInputEvent* motion_event);
+
/**
* Creates a native AInputEvent* object that is a copy of the specified Java
* android.view.MotionEvent. The result may be used with generic and MotionEvent-specific
diff --git a/include/input/Input.h b/include/input/Input.h
index e421dee275..2837add22c 100644
--- a/include/input/Input.h
+++ b/include/input/Input.h
@@ -275,23 +275,21 @@ enum {
/**
* Classifications of the current gesture, if available.
- *
- * The following values must be kept in sync with MotionEvent.java
*/
enum class MotionClassification : uint8_t {
/**
* No classification is available.
*/
- NONE = 0,
+ NONE = AMOTION_EVENT_CLASSIFICATION_NONE,
/**
* Too early to classify the current gesture. Need more events. Look for changes in the
* upcoming motion events.
*/
- AMBIGUOUS_GESTURE = 1,
+ AMBIGUOUS_GESTURE = AMOTION_EVENT_CLASSIFICATION_AMBIGUOUS_GESTURE,
/**
* The current gesture likely represents a user intentionally exerting force on the touchscreen.
*/
- DEEP_PRESS = 2,
+ DEEP_PRESS = AMOTION_EVENT_CLASSIFICATION_DEEP_PRESS,
};
/**
--
cgit v1.2.3-59-g8ed1b
From f4dc39f6b3f7a464fb111f3a51a9d44b9fcb29a6 Mon Sep 17 00:00:00 2001
From: Rachel Lee
Date: Tue, 15 Feb 2022 18:30:59 -0800
Subject: Rename to VsyncCallback & presentation time.
Bug: 217370454
Test: atest ChoreographerNativeTest
Change-Id: Id26497b0f94845e392778954039996b9bbab834f
---
include/android/choreographer.h | 8 ++---
libs/nativedisplay/AChoreographer.cpp | 37 +++++++++++-----------
.../private/android/choreographer.h | 7 ++--
libs/nativedisplay/libnativedisplay.map.txt | 8 ++---
4 files changed, 29 insertions(+), 31 deletions(-)
(limited to 'include/android')
diff --git a/include/android/choreographer.h b/include/android/choreographer.h
index 98f0eec8cc..63aa7ff6c0 100644
--- a/include/android/choreographer.h
+++ b/include/android/choreographer.h
@@ -76,7 +76,7 @@ typedef void (*AChoreographer_frameCallback64)(int64_t frameTimeNanos, void* dat
* It's passed the frame data that should not outlive the callback, as well as the data pointer
* provided by the application that registered a callback.
*/
-typedef void (*AChoreographer_extendedFrameCallback)(
+typedef void (*AChoreographer_vsyncCallback)(
const AChoreographerFrameCallbackData* callbackData, void* data);
/**
@@ -134,8 +134,8 @@ void AChoreographer_postFrameCallbackDelayed64(AChoreographer* choreographer,
* Posts a callback to run on the next frame. The data pointer provided will
* be passed to the callback function when it's called.
*/
-void AChoreographer_postExtendedFrameCallback(AChoreographer* choreographer,
- AChoreographer_extendedFrameCallback callback, void* data)
+void AChoreographer_postVsyncCallback(AChoreographer* choreographer,
+ AChoreographer_vsyncCallback callback, void* data)
__INTRODUCED_IN(33);
/**
@@ -215,7 +215,7 @@ AVsyncId AChoreographerFrameCallbackData_getFrameTimelineVsyncId(
/**
* The time in nanoseconds which the frame at given index is expected to be presented.
*/
-int64_t AChoreographerFrameCallbackData_getFrameTimelineExpectedPresentTimeNanos(
+int64_t AChoreographerFrameCallbackData_getFrameTimelineExpectedPresentationTimeNanos(
const AChoreographerFrameCallbackData* data, size_t index) __INTRODUCED_IN(33);
/**
diff --git a/libs/nativedisplay/AChoreographer.cpp b/libs/nativedisplay/AChoreographer.cpp
index 3ce381b122..a3eebdd5ee 100644
--- a/libs/nativedisplay/AChoreographer.cpp
+++ b/libs/nativedisplay/AChoreographer.cpp
@@ -78,7 +78,7 @@ using gui::VsyncEventData;
struct FrameCallback {
AChoreographer_frameCallback callback;
AChoreographer_frameCallback64 callback64;
- AChoreographer_extendedFrameCallback extendedCallback;
+ AChoreographer_vsyncCallback vsyncCallback;
void* data;
nsecs_t dueTime;
@@ -121,7 +121,7 @@ public:
explicit Choreographer(const sp& looper) EXCLUDES(gChoreographers.lock);
void postFrameCallbackDelayed(AChoreographer_frameCallback cb,
AChoreographer_frameCallback64 cb64,
- AChoreographer_extendedFrameCallback extendedCallback, void* data,
+ AChoreographer_vsyncCallback vsyncCallback, void* data,
nsecs_t delay);
void registerRefreshRateCallback(AChoreographer_refreshRateCallback cb, void* data)
EXCLUDES(gChoreographers.lock);
@@ -230,10 +230,10 @@ Choreographer::~Choreographer() {
void Choreographer::postFrameCallbackDelayed(AChoreographer_frameCallback cb,
AChoreographer_frameCallback64 cb64,
- AChoreographer_extendedFrameCallback extendedCallback,
- void* data, nsecs_t delay) {
+ AChoreographer_vsyncCallback vsyncCallback, void* data,
+ nsecs_t delay) {
nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
- FrameCallback callback{cb, cb64, extendedCallback, data, now + delay};
+ FrameCallback callback{cb, cb64, vsyncCallback, data, now + delay};
{
std::lock_guard _l{mLock};
mFrameCallbacks.push(callback);
@@ -389,13 +389,13 @@ void Choreographer::dispatchVsync(nsecs_t timestamp, PhysicalDisplayId, uint32_t
}
mLastVsyncEventData = vsyncEventData;
for (const auto& cb : callbacks) {
- if (cb.extendedCallback != nullptr) {
+ if (cb.vsyncCallback != nullptr) {
const ChoreographerFrameCallbackDataImpl frameCallbackData =
createFrameCallbackData(timestamp);
mInCallback = true;
- cb.extendedCallback(reinterpret_cast(
- &frameCallbackData),
- cb.data);
+ cb.vsyncCallback(reinterpret_cast(
+ &frameCallbackData),
+ cb.data);
mInCallback = false;
} else if (cb.callback64 != nullptr) {
cb.callback64(timestamp, cb.data);
@@ -522,10 +522,9 @@ void AChoreographer_routePostFrameCallbackDelayed64(AChoreographer* choreographe
void* data, uint32_t delayMillis) {
return AChoreographer_postFrameCallbackDelayed64(choreographer, callback, data, delayMillis);
}
-void AChoreographer_routePostExtendedFrameCallback(AChoreographer* choreographer,
- AChoreographer_extendedFrameCallback callback,
- void* data) {
- return AChoreographer_postExtendedFrameCallback(choreographer, callback, data);
+void AChoreographer_routePostVsyncCallback(AChoreographer* choreographer,
+ AChoreographer_vsyncCallback callback, void* data) {
+ return AChoreographer_postVsyncCallback(choreographer, callback, data);
}
void AChoreographer_routeRegisterRefreshRateCallback(AChoreographer* choreographer,
AChoreographer_refreshRateCallback callback,
@@ -553,9 +552,10 @@ AVsyncId AChoreographerFrameCallbackData_routeGetFrameTimelineVsyncId(
const AChoreographerFrameCallbackData* data, size_t index) {
return AChoreographerFrameCallbackData_getFrameTimelineVsyncId(data, index);
}
-int64_t AChoreographerFrameCallbackData_routeGetFrameTimelineExpectedPresentTimeNanos(
+int64_t AChoreographerFrameCallbackData_routeGetFrameTimelineExpectedPresentationTimeNanos(
const AChoreographerFrameCallbackData* data, size_t index) {
- return AChoreographerFrameCallbackData_getFrameTimelineExpectedPresentTimeNanos(data, index);
+ return AChoreographerFrameCallbackData_getFrameTimelineExpectedPresentationTimeNanos(data,
+ index);
}
int64_t AChoreographerFrameCallbackData_routeGetFrameTimelineDeadlineNanos(
const AChoreographerFrameCallbackData* data, size_t index) {
@@ -589,9 +589,8 @@ void AChoreographer_postFrameCallbackDelayed(AChoreographer* choreographer,
AChoreographer_to_Choreographer(choreographer)
->postFrameCallbackDelayed(callback, nullptr, nullptr, data, ms2ns(delayMillis));
}
-void AChoreographer_postExtendedFrameCallback(AChoreographer* choreographer,
- AChoreographer_extendedFrameCallback callback,
- void* data) {
+void AChoreographer_postVsyncCallback(AChoreographer* choreographer,
+ AChoreographer_vsyncCallback callback, void* data) {
AChoreographer_to_Choreographer(choreographer)
->postFrameCallbackDelayed(nullptr, nullptr, callback, data, 0);
}
@@ -650,7 +649,7 @@ AVsyncId AChoreographerFrameCallbackData_getFrameTimelineVsyncId(
LOG_ALWAYS_FATAL_IF(index >= VsyncEventData::kFrameTimelinesLength, "Index out of bounds");
return frameCallbackData->vsyncEventData.frameTimelines[index].vsyncId;
}
-int64_t AChoreographerFrameCallbackData_getFrameTimelineExpectedPresentTimeNanos(
+int64_t AChoreographerFrameCallbackData_getFrameTimelineExpectedPresentationTimeNanos(
const AChoreographerFrameCallbackData* data, size_t index) {
const ChoreographerFrameCallbackDataImpl* frameCallbackData =
AChoreographerFrameCallbackData_to_ChoreographerFrameCallbackDataImpl(data);
diff --git a/libs/nativedisplay/include-private/private/android/choreographer.h b/libs/nativedisplay/include-private/private/android/choreographer.h
index d650c26605..19be5bd4eb 100644
--- a/libs/nativedisplay/include-private/private/android/choreographer.h
+++ b/libs/nativedisplay/include-private/private/android/choreographer.h
@@ -50,9 +50,8 @@ void AChoreographer_routePostFrameCallback64(AChoreographer* choreographer,
void AChoreographer_routePostFrameCallbackDelayed64(AChoreographer* choreographer,
AChoreographer_frameCallback64 callback,
void* data, uint32_t delayMillis);
-void AChoreographer_routePostExtendedFrameCallback(AChoreographer* choreographer,
- AChoreographer_extendedFrameCallback callback,
- void* data);
+void AChoreographer_routePostVsyncCallback(AChoreographer* choreographer,
+ AChoreographer_vsyncCallback callback, void* data);
void AChoreographer_routeRegisterRefreshRateCallback(AChoreographer* choreographer,
AChoreographer_refreshRateCallback callback,
void* data);
@@ -67,7 +66,7 @@ size_t AChoreographerFrameCallbackData_routeGetPreferredFrameTimelineIndex(
const AChoreographerFrameCallbackData* data);
AVsyncId AChoreographerFrameCallbackData_routeGetFrameTimelineVsyncId(
const AChoreographerFrameCallbackData* data, size_t index);
-int64_t AChoreographerFrameCallbackData_routeGetFrameTimelineExpectedPresentTimeNanos(
+int64_t AChoreographerFrameCallbackData_routeGetFrameTimelineExpectedPresentationTimeNanos(
const AChoreographerFrameCallbackData* data, size_t index);
int64_t AChoreographerFrameCallbackData_routeGetFrameTimelineDeadlineNanos(
const AChoreographerFrameCallbackData* data, size_t index);
diff --git a/libs/nativedisplay/libnativedisplay.map.txt b/libs/nativedisplay/libnativedisplay.map.txt
index 657931342d..2da10cdc46 100644
--- a/libs/nativedisplay/libnativedisplay.map.txt
+++ b/libs/nativedisplay/libnativedisplay.map.txt
@@ -7,12 +7,12 @@ LIBNATIVEDISPLAY {
AChoreographer_postFrameCallbackDelayed64; # apex # introduced=30
AChoreographer_registerRefreshRateCallback; # apex # introduced=30
AChoreographer_unregisterRefreshRateCallback; # apex # introduced=30
- AChoreographer_postExtendedFrameCallback; # apex # introduced=33
+ AChoreographer_postVsyncCallback; # apex # introduced=33
AChoreographerFrameCallbackData_getFrameTimeNanos; # apex # introduced=33
AChoreographerFrameCallbackData_getFrameTimelinesLength; # apex # introduced=33
AChoreographerFrameCallbackData_getPreferredFrameTimelineIndex; # apex # introduced=33
AChoreographerFrameCallbackData_getFrameTimelineVsyncId; # apex # introduced=33
- AChoreographerFrameCallbackData_getFrameTimelineExpectedPresentTimeNanos; # apex # introduced=33
+ AChoreographerFrameCallbackData_getFrameTimelineExpectedPresentationTimeNanos; # apex # introduced=33
AChoreographerFrameCallbackData_getFrameTimelineDeadlineNanos; # apex # introduced=33
AChoreographer_create; # apex # introduced=30
AChoreographer_destroy; # apex # introduced=30
@@ -35,12 +35,12 @@ LIBNATIVEDISPLAY_PLATFORM {
android::AChoreographer_routePostFrameCallbackDelayed64*;
android::AChoreographer_routeRegisterRefreshRateCallback*;
android::AChoreographer_routeUnregisterRefreshRateCallback*;
- android::AChoreographer_routePostExtendedFrameCallback*;
+ android::AChoreographer_routePostVsyncCallback*;
android::AChoreographerFrameCallbackData_routeGetFrameTimeNanos*;
android::AChoreographerFrameCallbackData_routeGetFrameTimelinesLength*;
android::AChoreographerFrameCallbackData_routeGetPreferredFrameTimelineIndex*;
android::AChoreographerFrameCallbackData_routeGetFrameTimelineVsyncId*;
- android::AChoreographerFrameCallbackData_routeGetFrameTimelineExpectedPresentTimeNanos*;
+ android::AChoreographerFrameCallbackData_routeGetFrameTimelineExpectedPresentationTimeNanos*;
android::AChoreographerFrameCallbackData_routeGetFrameTimelineDeadlineNanos*;
android::AChoreographer_signalRefreshRateCallbacks*;
android::AChoreographer_getFrameInterval*;
--
cgit v1.2.3-59-g8ed1b
From b1f7795338af549f22ca8d06809b268dec4f456b Mon Sep 17 00:00:00 2001
From: Erik Staats
Date: Fri, 25 Mar 2022 11:49:58 -0700
Subject: Add note on when to call ASensorManager_getDynamicSensorList
Bug: 224562870
Test: N/A. Just a change in the comments.
Change-Id: Ia07fb3aac507a616c585c4e28106a04afea9605a
---
include/android/sensor.h | 11 +++++++++++
1 file changed, 11 insertions(+)
(limited to 'include/android')
diff --git a/include/android/sensor.h b/include/android/sensor.h
index c714b05dd7..6112d5fd0a 100644
--- a/include/android/sensor.h
+++ b/include/android/sensor.h
@@ -212,6 +212,13 @@ enum {
* {@link ASENSOR_TYPE_HEART_BEAT}
*/
ASENSOR_TYPE_HEART_BEAT = 31,
+ /**
+ * A constant describing a dynamic sensor meta event sensor.
+ *
+ * A sensor event of this type is received when a dynamic sensor is added to or removed from
+ * the system. This sensor type should always use special trigger report mode.
+ */
+ ASENSOR_TYPE_DYNAMIC_SENSOR_META = 32,
/**
* This sensor type is for delivering additional sensor information aside
* from sensor event data.
@@ -761,6 +768,10 @@ int ASensorManager_getSensorList(ASensorManager* manager, ASensorList* list);
* Each time this is called, the previously returned list is deallocated and
* must no longer be used.
*
+ * Clients should call this if they receive a sensor update from
+ * {@link ASENSOR_TYPE_DYNAMIC_SENSOR_META} indicating the sensors have changed.
+ * If this happens, previously received lists from this method will be stale.
+ *
* Available since API level 33.
*
* \param manager the {@link ASensorManager} instance obtained from
--
cgit v1.2.3-59-g8ed1b
From 1ad281cea344d412d00d9806b75292b08cbd50be Mon Sep 17 00:00:00 2001
From: Vaibhav Devmurari
Date: Thu, 17 Mar 2022 14:21:39 +0000
Subject: [API Review] Make changes to documentation for getActionButton and
getClassification APIs
Test: atest android.view.cts.MotionEventTest
Bug: 224565087
Change-Id: I23e7941b3372e2eaafbcc136460ec09c94c3ccbf
(cherry picked from commit 38fae2ad25efa26f4a3173ee0b8867bbb655ea00)
---
include/android/input.h | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
(limited to 'include/android')
diff --git a/include/android/input.h b/include/android/input.h
index fb5e204450..38b27bc587 100644
--- a/include/android/input.h
+++ b/include/android/input.h
@@ -810,7 +810,7 @@ enum {
/**
* Constants that identify different gesture classification types.
*/
-enum {
+enum AMotionClassification : uint32_t {
/**
* Classification constant: None.
*
@@ -820,7 +820,8 @@ enum {
/**
* Classification constant: Ambiguous gesture.
*
- * The user's intent with respect to the current event stream is not yet determined.
+ * The user's intent with respect to the current event stream is not yet determined. Events
+ * starting in AMBIGUOUS_GESTURE will eventually resolve into either DEEP_PRESS or NONE.
* Gestural actions, such as scrolling, should be inhibited until the classification resolves
* to another value or the event stream ends.
*/
@@ -1357,8 +1358,17 @@ float AMotionEvent_getHistoricalAxisValue(const AInputEvent* motion_event,
* Get the action button for the motion event. Returns a valid action button when the
* event is associated with a button press or button release action. For other actions
* the return value is undefined.
+ *
+ * @see #AMOTION_EVENT_BUTTON_PRIMARY
+ * @see #AMOTION_EVENT_BUTTON_SECONDARY
+ * @see #AMOTION_EVENT_BUTTON_TERTIARY
+ * @see #AMOTION_EVENT_BUTTON_BACK
+ * @see #AMOTION_EVENT_BUTTON_FORWARD
+ * @see #AMOTION_EVENT_BUTTON_STYLUS_PRIMARY
+ * @see #AMOTION_EVENT_BUTTON_STYLUS_SECONDARY
*/
-int32_t AMotionEvent_getActionButton(const AInputEvent* motion_event);
+int32_t AMotionEvent_getActionButton(const AInputEvent* motion_event)
+ __INTRODUCED_IN(__ANDROID_API_T__);
/**
* Returns the classification for the current gesture.
@@ -1368,7 +1378,8 @@ int32_t AMotionEvent_getActionButton(const AInputEvent* motion_event);
* @see #AMOTION_EVENT_CLASSIFICATION_AMBIGUOUS_GESTURE
* @see #AMOTION_EVENT_CLASSIFICATION_DEEP_PRESS
*/
-int32_t AMotionEvent_getClassification(const AInputEvent* motion_event);
+int32_t AMotionEvent_getClassification(const AInputEvent* motion_event)
+ __INTRODUCED_IN(__ANDROID_API_T__);
/**
* Creates a native AInputEvent* object that is a copy of the specified Java
--
cgit v1.2.3-59-g8ed1b
From 4a4d046deca902981ece1ddfdac88e6fa4c76398 Mon Sep 17 00:00:00 2001
From: Brian Duddie
Date: Mon, 9 May 2022 16:49:49 -0700
Subject: Limit access to head tracker sensor
Lock down access to only internal system usage and CTS due to privacy
considerations.
Bug: 224619073
Test: run SensorHeadTrackerTest with and without "cmd unrestrict-ht"
Change-Id: I0bd37472e058c550de8d0098caa0bd439d8f12a5
---
include/android/sensor.h | 3 ++-
services/sensorservice/SensorDirectConnection.cpp | 2 +-
services/sensorservice/SensorEventConnection.cpp | 3 ++-
services/sensorservice/SensorService.cpp | 26 ++++++++++++++++++++---
services/sensorservice/SensorService.h | 6 +++++-
5 files changed, 33 insertions(+), 7 deletions(-)
(limited to 'include/android')
diff --git a/include/android/sensor.h b/include/android/sensor.h
index 6112d5fd0a..eef69f4b32 100644
--- a/include/android/sensor.h
+++ b/include/android/sensor.h
@@ -267,7 +267,8 @@ enum {
* {@link ASENSOR_TYPE_HEAD_TRACKER}
* reporting-mode: continuous
*
- * Measures the orientation and rotational velocity of a user's head.
+ * Measures the orientation and rotational velocity of a user's head. Only for internal use
+ * within the Android system.
*/
ASENSOR_TYPE_HEAD_TRACKER = 37,
/**
diff --git a/services/sensorservice/SensorDirectConnection.cpp b/services/sensorservice/SensorDirectConnection.cpp
index fae16f66b2..2dd12e9446 100644
--- a/services/sensorservice/SensorDirectConnection.cpp
+++ b/services/sensorservice/SensorDirectConnection.cpp
@@ -157,7 +157,7 @@ int32_t SensorService::SensorDirectConnection::configureChannel(int handle, int
}
const Sensor& s = si->getSensor();
- if (!SensorService::canAccessSensor(s, "config direct channel", mOpPackageName)) {
+ if (!mService->canAccessSensor(s, "config direct channel", mOpPackageName)) {
return PERMISSION_DENIED;
}
diff --git a/services/sensorservice/SensorEventConnection.cpp b/services/sensorservice/SensorEventConnection.cpp
index 6948895835..f06f9472bd 100644
--- a/services/sensorservice/SensorEventConnection.cpp
+++ b/services/sensorservice/SensorEventConnection.cpp
@@ -162,7 +162,8 @@ bool SensorService::SensorEventConnection::addSensor(int32_t handle) {
Mutex::Autolock _l(mConnectionLock);
sp si = mService->getSensorInterfaceFromHandle(handle);
if (si == nullptr ||
- !canAccessSensor(si->getSensor(), "Add to SensorEventConnection: ", mOpPackageName) ||
+ !mService->canAccessSensor(si->getSensor(), "Add to SensorEventConnection: ",
+ mOpPackageName) ||
mSensorInfo.count(handle) > 0) {
return false;
}
diff --git a/services/sensorservice/SensorService.cpp b/services/sensorservice/SensorService.cpp
index 88cf5ab25a..948692bd47 100644
--- a/services/sensorservice/SensorService.cpp
+++ b/services/sensorservice/SensorService.cpp
@@ -814,6 +814,12 @@ status_t SensorService::shellCommand(int in, int out, int err, Vector&
return handleResetUidState(args, err);
} else if (args[0] == String16("get-uid-state")) {
return handleGetUidState(args, out, err);
+ } else if (args[0] == String16("unrestrict-ht")) {
+ mHtRestricted = false;
+ return NO_ERROR;
+ } else if (args[0] == String16("restrict-ht")) {
+ mHtRestricted = true;
+ return NO_ERROR;
} else if (args.size() == 1 && args[0] == String16("help")) {
printHelp(out);
return NO_ERROR;
@@ -1338,11 +1344,11 @@ Vector SensorService::getSensorList(const String16& opPackageName) {
Vector SensorService::getDynamicSensorList(const String16& opPackageName) {
Vector accessibleSensorList;
mSensors.forEachSensor(
- [&opPackageName, &accessibleSensorList] (const Sensor& sensor) -> bool {
+ [this, &opPackageName, &accessibleSensorList] (const Sensor& sensor) -> bool {
if (sensor.isDynamicSensor()) {
- if (canAccessSensor(sensor, "getDynamicSensorList", opPackageName)) {
+ if (canAccessSensor(sensor, "can't see", opPackageName)) {
accessibleSensorList.add(sensor);
- } else {
+ } else if (sensor.getType() != SENSOR_TYPE_HEAD_TRACKER) {
ALOGI("Skipped sensor %s because it requires permission %s and app op %" PRId32,
sensor.getName().string(),
sensor.getRequiredPermission().string(),
@@ -1989,6 +1995,20 @@ status_t SensorService::flushSensor(const sp& connection,
bool SensorService::canAccessSensor(const Sensor& sensor, const char* operation,
const String16& opPackageName) {
+ // Special case for Head Tracker sensor type: currently restricted to system usage only, unless
+ // the restriction is specially lifted for testing
+ if (sensor.getType() == SENSOR_TYPE_HEAD_TRACKER &&
+ !isAudioServerOrSystemServerUid(IPCThreadState::self()->getCallingUid())) {
+ if (!mHtRestricted) {
+ ALOGI("Permitting access to HT sensor type outside system (%s)",
+ String8(opPackageName).string());
+ } else {
+ ALOGW("%s %s a sensor (%s) as a non-system client", String8(opPackageName).string(),
+ operation, sensor.getName().string());
+ return false;
+ }
+ }
+
// Check if a permission is required for this sensor
if (sensor.getRequiredPermission().length() <= 0) {
return true;
diff --git a/services/sensorservice/SensorService.h b/services/sensorservice/SensorService.h
index b18d20418f..234dc9cd7d 100644
--- a/services/sensorservice/SensorService.h
+++ b/services/sensorservice/SensorService.h
@@ -373,7 +373,7 @@ private:
status_t cleanupWithoutDisableLocked(const sp& connection, int handle);
void cleanupAutoDisabledSensorLocked(const sp& connection,
sensors_event_t const* buffer, const int count);
- static bool canAccessSensor(const Sensor& sensor, const char* operation,
+ bool canAccessSensor(const Sensor& sensor, const char* operation,
const String16& opPackageName);
static bool hasPermissionForSensor(const Sensor& sensor);
static int getTargetSdkVersion(const String16& opPackageName);
@@ -492,6 +492,10 @@ private:
std::unordered_map mRecentEvent;
Mode mCurrentOperatingMode;
+ // true if the head tracker sensor type is currently restricted to system usage only
+ // (can only be unrestricted for testing, via shell cmd)
+ bool mHtRestricted = true;
+
// This packagaName is set when SensorService is in RESTRICTED or DATA_INJECTION mode. Only
// applications with this packageName are allowed to activate/deactivate or call flush on
// sensors. To run CTS this is can be set to ".cts." and only CTS tests will get access to
--
cgit v1.2.3-59-g8ed1b