From 0277d0a89febb1768cd423ad0324101720d582c4 Mon Sep 17 00:00:00 2001 From: Ryan Prichard Date: Thu, 19 Jul 2018 20:32:19 -0700 Subject: Restore __ANDROID_API__ guards for core APIs This commit restores the __ANDROID_API__ guards removed in "Add __INTRODUCED_IN to core APIs.", commit 9db409b053460e065cefb1d1caefe048f90cfff0. Add a guard to surface_texture.h. In choreographer.h, declare the types even for older APIs. Bug: http://b/111668906 Test: builds Change-Id: Ia013f48a109310f9f8ca6a3211f28fcb69dd602d (cherry picked from commit 92b1ebea095f9cac70b81ae7382ae69583c9914d) --- include/android/choreographer.h | 4 ++++ include/android/configuration.h | 4 ++++ include/android/input.h | 8 ++++++++ include/android/multinetwork.h | 4 ++++ include/android/native_window_jni.h | 2 ++ include/android/sensor.h | 12 +++++++++++- include/android/sharedmem.h | 5 +++++ include/android/sharedmem_jni.h | 5 +++++ include/android/surface_texture.h | 5 +++++ include/android/trace.h | 4 ++++ 10 files changed, 52 insertions(+), 1 deletion(-) diff --git a/include/android/choreographer.h b/include/android/choreographer.h index 11f8f6b0c7..d75de1ee1a 100644 --- a/include/android/choreographer.h +++ b/include/android/choreographer.h @@ -43,6 +43,8 @@ typedef struct AChoreographer AChoreographer; */ typedef void (*AChoreographer_frameCallback)(long frameTimeNanos, void* data); +#if __ANDROID_API__ >= 24 + /** * Get the AChoreographer instance for the current thread. This must be called * on an ALooper thread. @@ -65,6 +67,8 @@ void AChoreographer_postFrameCallbackDelayed(AChoreographer* choreographer, AChoreographer_frameCallback callback, void* data, long delayMillis) __INTRODUCED_IN(24); +#endif /* __ANDROID_API__ >= 24 */ + __END_DECLS #endif // ANDROID_CHOREOGRAPHER_H diff --git a/include/android/configuration.h b/include/android/configuration.h index 81aedca9d8..ef6c5a2f81 100644 --- a/include/android/configuration.h +++ b/include/android/configuration.h @@ -675,6 +675,7 @@ int32_t AConfiguration_getUiModeNight(AConfiguration* config); */ void AConfiguration_setUiModeNight(AConfiguration* config, int32_t uiModeNight); +#if __ANDROID_API__ >= 13 /** * Return the current configuration screen width in dp units, or * ACONFIGURATION_SCREEN_WIDTH_DP_ANY if not set. @@ -707,7 +708,9 @@ int32_t AConfiguration_getSmallestScreenWidthDp(AConfiguration* config) __INTROD * Set the configuration's smallest screen width in dp units. */ void AConfiguration_setSmallestScreenWidthDp(AConfiguration* config, int32_t value) __INTRODUCED_IN(13); +#endif /* __ANDROID_API__ >= 13 */ +#if __ANDROID_API__ >= 17 /** * Return the configuration's layout direction, or * ACONFIGURATION_LAYOUTDIR_ANY if not set. @@ -718,6 +721,7 @@ int32_t AConfiguration_getLayoutDirection(AConfiguration* config) __INTRODUCED_I * Set the configuration's layout direction. */ 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/input.h b/include/android/input.h index 1e49b7a16d..681090188f 100644 --- a/include/android/input.h +++ b/include/android/input.h @@ -986,8 +986,10 @@ int32_t AMotionEvent_getFlags(const AInputEvent* motion_event); */ int32_t AMotionEvent_getMetaState(const AInputEvent* motion_event); +#if __ANDROID_API__ >= 14 /** Get the button state of all buttons that are pressed. */ int32_t AMotionEvent_getButtonState(const AInputEvent* motion_event) __INTRODUCED_IN(14); +#endif /** * Get a bitfield indicating which edges, if any, were touched by this motion event. @@ -1052,12 +1054,14 @@ size_t AMotionEvent_getPointerCount(const AInputEvent* motion_event); */ int32_t AMotionEvent_getPointerId(const AInputEvent* motion_event, size_t pointer_index); +#if __ANDROID_API__ >= 14 /** * Get the tool type of a pointer for the given pointer index. * The tool type indicates the type of tool used to make contact such as a * finger or stylus, if known. */ int32_t AMotionEvent_getToolType(const AInputEvent* motion_event, size_t pointer_index) __INTRODUCED_IN(14); +#endif /** * Get the original raw X coordinate of this event. @@ -1147,9 +1151,11 @@ float AMotionEvent_getToolMinor(const AInputEvent* motion_event, size_t pointer_ */ float AMotionEvent_getOrientation(const AInputEvent* motion_event, size_t pointer_index); +#if __ANDROID_API__ >= 13 /** Get the value of the request axis for the given pointer index. */ float AMotionEvent_getAxisValue(const AInputEvent* motion_event, int32_t axis, size_t pointer_index) __INTRODUCED_IN(13); +#endif /** * Get the number of historical points in this event. These are movements that @@ -1280,12 +1286,14 @@ float AMotionEvent_getHistoricalToolMinor(const AInputEvent* motion_event, size_ float AMotionEvent_getHistoricalOrientation(const AInputEvent* motion_event, size_t pointer_index, size_t history_index); +#if __ANDROID_API__ >= 13 /** * Get the historical value of the request axis for the given pointer index * that occurred between this event and the previous motion event. */ float AMotionEvent_getHistoricalAxisValue(const AInputEvent* motion_event, int32_t axis, size_t pointer_index, size_t history_index) __INTRODUCED_IN(13); +#endif struct AInputQueue; diff --git a/include/android/multinetwork.h b/include/android/multinetwork.h index 55df9f85c3..4d24680246 100644 --- a/include/android/multinetwork.h +++ b/include/android/multinetwork.h @@ -60,6 +60,8 @@ 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. * @@ -106,6 +108,8 @@ 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 */ + __END_DECLS #endif // ANDROID_MULTINETWORK_H diff --git a/include/android/native_window_jni.h b/include/android/native_window_jni.h index 74e43c77b9..0c196b9671 100644 --- a/include/android/native_window_jni.h +++ b/include/android/native_window_jni.h @@ -44,6 +44,7 @@ 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 @@ -52,6 +53,7 @@ ANativeWindow* ANativeWindow_fromSurface(JNIEnv* env, jobject surface); * collected. */ 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 59229c114f..005564d153 100644 --- a/include/android/sensor.h +++ b/include/android/sensor.h @@ -472,12 +472,13 @@ typedef ASensorRef const* ASensorList; * ASensorManager* sensorManager = ASensorManager_getInstance(); * */ -#if __ANDROID_API__ >= __ANDROID_API_O__ +#if __ANDROID_API__ >= 26 __attribute__ ((deprecated)) ASensorManager* ASensorManager_getInstance(); #else ASensorManager* ASensorManager_getInstance(); #endif +#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. @@ -488,6 +489,7 @@ ASensorManager* ASensorManager_getInstance(); * */ ASensorManager* ASensorManager_getInstanceForPackage(const char* packageName) __INTRODUCED_IN(26); +#endif /** * Returns the list of available sensors. @@ -500,11 +502,13 @@ 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. */ 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. @@ -521,6 +525,7 @@ ASensorEventQueue* ASensorManager_createEventQueue(ASensorManager* manager, */ int ASensorManager_destroyEventQueue(ASensorManager* manager, ASensorEventQueue* queue); +#if __ANDROID_API__ >= 26 /** * Create direct channel based on shared memory * @@ -609,6 +614,7 @@ 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 */ /*****************************************************************************/ @@ -727,6 +733,7 @@ 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. @@ -752,7 +759,9 @@ int ASensor_getReportingMode(ASensor const* sensor) __INTRODUCED_IN(21); * Returns true if this is a wake up sensor, false otherwise. */ 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. * @@ -774,6 +783,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 */ #ifdef __cplusplus }; diff --git a/include/android/sharedmem.h b/include/android/sharedmem.h index 0354f17f48..b772f7093c 100644 --- a/include/android/sharedmem.h +++ b/include/android/sharedmem.h @@ -27,6 +27,7 @@ #define ANDROID_SHARED_MEMORY_H #include +#include /****************************************************************** * @@ -52,6 +53,8 @@ extern "C" { #endif +#if __ANDROID_API__ >= 26 + /** * Create a shared memory region. * @@ -106,6 +109,8 @@ 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 d8b514f680..e42f9a1c84 100644 --- a/include/android/sharedmem_jni.h +++ b/include/android/sharedmem_jni.h @@ -29,6 +29,7 @@ #include #include #include +#include /****************************************************************** * @@ -54,6 +55,8 @@ 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 @@ -70,6 +73,8 @@ 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_texture.h b/include/android/surface_texture.h index db10a1618e..a36e982c78 100644 --- a/include/android/surface_texture.h +++ b/include/android/surface_texture.h @@ -43,6 +43,7 @@ */ #include +#include #include @@ -58,6 +59,8 @@ struct ASurfaceTexture; */ typedef struct ASurfaceTexture ASurfaceTexture; +#if __ANDROID_API__ >= 28 + /** * Release the reference to the native ASurfaceTexture acquired with * ASurfaceTexture_fromSurfaceTexture(). @@ -157,6 +160,8 @@ 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/trace.h b/include/android/trace.h index 9f59acfaba..4d57d4f369 100644 --- a/include/android/trace.h +++ b/include/android/trace.h @@ -37,6 +37,8 @@ extern "C" { #endif +#if __ANDROID_API__ >= 23 + /** * Returns true if tracing is enabled. Use this signal to avoid expensive computation only necessary * when tracing is enabled. @@ -61,6 +63,8 @@ void ATrace_beginSection(const char* sectionName) __INTRODUCED_IN(23); */ void ATrace_endSection() __INTRODUCED_IN(23); +#endif /* __ANDROID_API__ >= 23 */ + #ifdef __cplusplus }; #endif -- cgit v1.2.3-59-g8ed1b From 35d9bfbf61b6cd553bc4a39bf5484dc7b42736b2 Mon Sep 17 00:00:00 2001 From: Ryan Prichard Date: Fri, 20 Jul 2018 15:29:55 -0700 Subject: Fix __ANDROID_API__ guards for libnativewindow Partial revert of: - "Add __INTRODUCED_IN to ." commit a2c9607eab7214db97e4a63fb18154d4dfd95284. - "Add __INTRODUCED_IN annotations to ." commit 493f4a23bf586bf1bcd5e9bc73ed3c94852fc199 Most of these APIs were available via libandroid.so in API 9. Bug: http://b/111668906 Bug: http://b/111660252 Test: m Change-Id: I40874c4cd3413abf26f74f21caa5fb845fab721b (cherry picked from commit 733e443cc01c3a3d5bf756976c1a4599c236e1ef) --- .../nativewindow/include/android/hardware_buffer.h | 4 ++++ libs/nativewindow/include/android/native_window.h | 28 ++++++++++++---------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/libs/nativewindow/include/android/hardware_buffer.h b/libs/nativewindow/include/android/hardware_buffer.h index 080387baf0..9ca49412fd 100644 --- a/libs/nativewindow/include/android/hardware_buffer.h +++ b/libs/nativewindow/include/android/hardware_buffer.h @@ -215,6 +215,8 @@ typedef struct AHardwareBuffer_Desc { typedef struct AHardwareBuffer AHardwareBuffer; +#if __ANDROID_API__ >= 26 + /** * Allocates a buffer that backs an AHardwareBuffer using the passed * AHardwareBuffer_Desc. @@ -307,6 +309,8 @@ int AHardwareBuffer_sendHandleToUnixSocket(const AHardwareBuffer* buffer, int so */ int AHardwareBuffer_recvHandleFromUnixSocket(int socketFd, AHardwareBuffer** outBuffer) __INTRODUCED_IN(26); +#endif // __ANDROID_API__ >= 26 + __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 78d32e430c..6831f9176d 100644 --- a/libs/nativewindow/include/android/native_window.h +++ b/libs/nativewindow/include/android/native_window.h @@ -109,33 +109,33 @@ typedef struct ANativeWindow_Buffer { * Acquire a reference on the given {@link ANativeWindow} object. This prevents the object * from being deleted until the reference is removed. */ -void ANativeWindow_acquire(ANativeWindow* window) __INTRODUCED_IN(26); +void ANativeWindow_acquire(ANativeWindow* window); /** * Remove a reference that was previously acquired with {@link ANativeWindow_acquire()}. */ -void ANativeWindow_release(ANativeWindow* window) __INTRODUCED_IN(26); +void ANativeWindow_release(ANativeWindow* window); /** * Return the current width in pixels of the window surface. * * \return negative value on error. */ -int32_t ANativeWindow_getWidth(ANativeWindow* window) __INTRODUCED_IN(26); +int32_t ANativeWindow_getWidth(ANativeWindow* window); /** * Return the current height in pixels of the window surface. * * \return a negative value on error. */ -int32_t ANativeWindow_getHeight(ANativeWindow* window) __INTRODUCED_IN(26); +int32_t ANativeWindow_getHeight(ANativeWindow* window); /** * Return the current pixel format (AHARDWAREBUFFER_FORMAT_*) of the window surface. * * \return a negative value on error. */ -int32_t ANativeWindow_getFormat(ANativeWindow* window) __INTRODUCED_IN(26); +int32_t ANativeWindow_getFormat(ANativeWindow* window); /** * Change the format and size of the window buffers. @@ -155,7 +155,7 @@ int32_t ANativeWindow_getFormat(ANativeWindow* window) __INTRODUCED_IN(26); * \return 0 for success, or a negative value on error. */ int32_t ANativeWindow_setBuffersGeometry(ANativeWindow* window, - int32_t width, int32_t height, int32_t format) __INTRODUCED_IN(26); + int32_t width, int32_t height, int32_t format); /** * Lock the window's next drawing surface for writing. @@ -168,7 +168,7 @@ int32_t ANativeWindow_setBuffersGeometry(ANativeWindow* window, * \return 0 for success, or a negative value on error. */ int32_t ANativeWindow_lock(ANativeWindow* window, ANativeWindow_Buffer* outBuffer, - ARect* inOutDirtyBounds) __INTRODUCED_IN(26); + ARect* inOutDirtyBounds); /** * Unlock the window's drawing surface after previously locking it, @@ -176,7 +176,9 @@ int32_t ANativeWindow_lock(ANativeWindow* window, ANativeWindow_Buffer* outBuffe * * \return 0 for success, or a negative value on error. */ -int32_t ANativeWindow_unlockAndPost(ANativeWindow* window) __INTRODUCED_IN(26); +int32_t ANativeWindow_unlockAndPost(ANativeWindow* window); + +#if __ANDROID_API__ >= 26 /** * Set a transform that will be applied to future buffers posted to the window. @@ -186,7 +188,9 @@ int32_t ANativeWindow_unlockAndPost(ANativeWindow* window) __INTRODUCED_IN(26); */ int32_t ANativeWindow_setBuffersTransform(ANativeWindow* window, int32_t transform) __INTRODUCED_IN(26); -#if __ANDROID_API__ >= __ANDROID_API_P__ +#endif // __ANDROID_API__ >= 26 + +#if __ANDROID_API__ >= 28 /** * All buffers queued after this call will be associated with the dataSpace @@ -202,16 +206,16 @@ int32_t ANativeWindow_setBuffersTransform(ANativeWindow* window, int32_t transfo * \return 0 for success, -EINVAL if window is invalid or the dataspace is not * supported. */ -int32_t ANativeWindow_setBuffersDataSpace(ANativeWindow* window, int32_t dataSpace); +int32_t ANativeWindow_setBuffersDataSpace(ANativeWindow* window, int32_t dataSpace) __INTRODUCED_IN(28); /** * Get the dataspace of the buffers in window. * \return the dataspace of buffers in window, ADATASPACE_UNKNOWN is returned if * dataspace is unknown, or -EINVAL if window is invalid. */ -int32_t ANativeWindow_getBuffersDataSpace(ANativeWindow* window); +int32_t ANativeWindow_getBuffersDataSpace(ANativeWindow* window) __INTRODUCED_IN(28); -#endif // __ANDROID_API__ >= __ANDROID_API_P__ +#endif // __ANDROID_API__ >= 28 #ifdef __cplusplus }; -- cgit v1.2.3-59-g8ed1b From 64b4621f4f54d7662561f52b17d995d4029cd7fa Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 27 Jul 2018 15:35:29 -0700 Subject: Fix doxygen syntax. Bug: N/A Test: N/A Change-Id: Ifef817a0d2885992d647b3b821b94bb509b3a274 --- include/android/surface_texture.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/android/surface_texture.h b/include/android/surface_texture.h index a36e982c78..540d23a4c7 100644 --- a/include/android/surface_texture.h +++ b/include/android/surface_texture.h @@ -76,7 +76,7 @@ void ASurfaceTexture_release(ASurfaceTexture* st) __INTRODUCED_IN(28); * \param st A ASurfaceTexture reference acquired with ASurfaceTexture_fromSurfaceTexture() * @return A reference to an ANativeWindow. This reference MUST BE released when no longer needed * using ANativeWindow_release(). Failing to do so will result in leaked resources. nullptr is - * returned if \st is null or if it's not an instance of android.graphics.SurfaceTexture + * returned if \p st is null or if it's not an instance of android.graphics.SurfaceTexture */ ANativeWindow* ASurfaceTexture_acquireANativeWindow(ASurfaceTexture* st) __INTRODUCED_IN(28); -- cgit v1.2.3-59-g8ed1b From 97eba51959585a932adeed0ef656b6c0627382dd Mon Sep 17 00:00:00 2001 From: Ian Elliott Date: Wed, 21 Mar 2018 15:35:55 -0600 Subject: Remove a no-longer-needed workaround from eglMakeCurrent Change Ids I857da78078dd212b523d690415cf525ecd463961 and I38f3450005a4eec5f1a684ee7d66363e88f6d92f added/refined a work-around for a buggy driver (that's no longer supported), and introduced a problem by swallowing eglMakeCurrent errors coming from the driver. This change removes the work-around, as the original author reported that it is no longer needed. Bug: 71505290 Bug: 111963599 Test: Build and install Change-Id: I0121edfa076667e3320ae2c3b95608c3482937a7 (cherry picked from commit 60d35a21165006f9fee9be25c7b2cb41f884d7cf) --- opengl/libs/EGL/eglApi.cpp | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/opengl/libs/EGL/eglApi.cpp b/opengl/libs/EGL/eglApi.cpp index c65bddfbb3..3312b031a0 100644 --- a/opengl/libs/EGL/eglApi.cpp +++ b/opengl/libs/EGL/eglApi.cpp @@ -1054,38 +1054,6 @@ EGLBoolean eglMakeCurrent( EGLDisplay dpy, EGLSurface draw, egl_tls_t::setContext(EGL_NO_CONTEXT); } } else { - - if (cur_c != NULL) { - // Force return to current context for drivers that cannot handle errors - EGLBoolean restore_result = EGL_FALSE; - // get a reference to the old current objects - ContextRef _c2(dp.get(), cur_c); - SurfaceRef _d2(dp.get(), cur_c->draw); - SurfaceRef _r2(dp.get(), cur_c->read); - - c = cur_c; - impl_ctx = c->context; - impl_draw = EGL_NO_SURFACE; - if (cur_c->draw != EGL_NO_SURFACE) { - d = get_surface(cur_c->draw); - impl_draw = d->surface; - } - impl_read = EGL_NO_SURFACE; - if (cur_c->read != EGL_NO_SURFACE) { - r = get_surface(cur_c->read); - impl_read = r->surface; - } - restore_result = dp->makeCurrent(c, cur_c, - cur_c->draw, cur_c->read, cur_c->context, - impl_draw, impl_read, impl_ctx); - if (restore_result == EGL_TRUE) { - _c2.acquire(); - _r2.acquire(); - _d2.acquire(); - } else { - ALOGE("Could not restore original EGL context"); - } - } // this will ALOGE the error egl_connection_t* const cnx = &gEGLImpl; result = setError(cnx->egl.eglGetError(), (EGLBoolean)EGL_FALSE); -- cgit v1.2.3-59-g8ed1b From cb2f0ceed876b3c1cc62fc677c75a12c1f10b199 Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Fri, 16 Nov 2018 22:18:53 -0800 Subject: Sanitize InputMessage before sending The struct InputMessage has many fields, and is force-aligned to 8-byte boundaries. There are also some padding fields that carry no information. This struct is typically allocated in the stack and populated with various values before being sent across as a stream of bytes through the socket. Therefore, the "unused" data portions of the struct could contain portions of the stack, since there aren't ever writes to those memory locations. To avoid this information leak, forcefully sanitize the struct. Create a new struct that is explicitly set to zero. Next, only fill the meaningful fields manually. Bug: 115739809 Test: cts-tradefed run cts -m CtsSecurityBulletinHostTestCases -t android.security.cts.Poc18_12; adb shell monkey 100000 Change-Id: I7e44dacf1e8fa3156c8e4d2f7784ef0c53dab507 Merged-In: I7e44dacf1e8fa3156c8e4d2f7784ef0c53dab507 --- include/input/InputTransport.h | 11 ++++ libs/input/InputTransport.cpp | 102 ++++++++++++++++++++++++++++++++- libs/input/tests/StructLayout_test.cpp | 3 + 3 files changed, 114 insertions(+), 2 deletions(-) diff --git a/include/input/InputTransport.h b/include/input/InputTransport.h index f31bceabd7..7d56bf5b46 100644 --- a/include/input/InputTransport.h +++ b/include/input/InputTransport.h @@ -42,6 +42,13 @@ namespace android { * * Note that this structure is used for IPCs so its layout must be identical * on 64 and 32 bit processes. This is tested in StructLayout_test.cpp. + * + * Since the struct must be aligned to an 8-byte boundary, there could be uninitialized bytes + * in-between the defined fields. This padding data should be explicitly accounted for by adding + * "empty" fields into the struct. This data is memset to zero before sending the struct across + * the socket. Adding the explicit fields ensures that the memset is not optimized away by the + * compiler. When a new field is added to the struct, the corresponding change + * in StructLayout_test should be made. */ struct InputMessage { enum { @@ -62,6 +69,7 @@ struct InputMessage { union Body { struct Key { uint32_t seq; + uint32_t empty1; nsecs_t eventTime __attribute__((aligned(8))); int32_t deviceId; int32_t source; @@ -80,6 +88,7 @@ struct InputMessage { struct Motion { uint32_t seq; + uint32_t empty1; nsecs_t eventTime __attribute__((aligned(8))); int32_t deviceId; int32_t source; @@ -95,6 +104,7 @@ struct InputMessage { float xPrecision; float yPrecision; uint32_t pointerCount; + uint32_t empty2; // Note that PointerCoords requires 8 byte alignment. struct Pointer { PointerProperties properties; @@ -125,6 +135,7 @@ struct InputMessage { bool isValid(size_t actualSize) const; size_t size() const; + void getSanitizedCopy(InputMessage* msg) const; }; /* diff --git a/libs/input/InputTransport.cpp b/libs/input/InputTransport.cpp index 2dff4e0918..f6d2c15633 100644 --- a/libs/input/InputTransport.cpp +++ b/libs/input/InputTransport.cpp @@ -97,6 +97,102 @@ size_t InputMessage::size() const { return sizeof(Header); } +/** + * There could be non-zero bytes in-between InputMessage fields. Force-initialize the entire + * memory to zero, then only copy the valid bytes on a per-field basis. + */ +void InputMessage::getSanitizedCopy(InputMessage* msg) const { + memset(msg, 0, sizeof(*msg)); + + // Write the header + msg->header.type = header.type; + + // Write the body + switch(header.type) { + case InputMessage::TYPE_KEY: { + // uint32_t seq + msg->body.key.seq = body.key.seq; + // nsecs_t eventTime + msg->body.key.eventTime = body.key.eventTime; + // int32_t deviceId + msg->body.key.deviceId = body.key.deviceId; + // int32_t source + msg->body.key.source = body.key.source; + // int32_t action + msg->body.key.action = body.key.action; + // int32_t flags + msg->body.key.flags = body.key.flags; + // int32_t keyCode + msg->body.key.keyCode = body.key.keyCode; + // int32_t scanCode + msg->body.key.scanCode = body.key.scanCode; + // int32_t metaState + msg->body.key.metaState = body.key.metaState; + // int32_t repeatCount + msg->body.key.repeatCount = body.key.repeatCount; + // nsecs_t downTime + msg->body.key.downTime = body.key.downTime; + break; + } + case InputMessage::TYPE_MOTION: { + // uint32_t seq + msg->body.motion.seq = body.motion.seq; + // nsecs_t eventTime + msg->body.motion.eventTime = body.motion.eventTime; + // int32_t deviceId + msg->body.motion.deviceId = body.motion.deviceId; + // int32_t source + msg->body.motion.source = body.motion.source; + // int32_t action + msg->body.motion.action = body.motion.action; + // int32_t actionButton + msg->body.motion.actionButton = body.motion.actionButton; + // int32_t flags + msg->body.motion.flags = body.motion.flags; + // int32_t metaState + msg->body.motion.metaState = body.motion.metaState; + // int32_t buttonState + msg->body.motion.buttonState = body.motion.buttonState; + // int32_t edgeFlags + msg->body.motion.edgeFlags = body.motion.edgeFlags; + // nsecs_t downTime + msg->body.motion.downTime = body.motion.downTime; + // float xOffset + msg->body.motion.xOffset = body.motion.xOffset; + // float yOffset + msg->body.motion.yOffset = body.motion.yOffset; + // float xPrecision + msg->body.motion.xPrecision = body.motion.xPrecision; + // float yPrecision + msg->body.motion.yPrecision = body.motion.yPrecision; + // uint32_t pointerCount + msg->body.motion.pointerCount = body.motion.pointerCount; + //struct Pointer pointers[MAX_POINTERS] + for (size_t i = 0; i < body.motion.pointerCount; i++) { + // PointerProperties properties + msg->body.motion.pointers[i].properties.id = body.motion.pointers[i].properties.id; + msg->body.motion.pointers[i].properties.toolType = + body.motion.pointers[i].properties.toolType, + // PointerCoords coords + msg->body.motion.pointers[i].coords.bits = body.motion.pointers[i].coords.bits; + const uint32_t count = BitSet64::count(body.motion.pointers[i].coords.bits); + memcpy(&msg->body.motion.pointers[i].coords.values[0], + &body.motion.pointers[i].coords.values[0], + count * (sizeof(body.motion.pointers[i].coords.values[0]))); + } + break; + } + case InputMessage::TYPE_FINISHED: { + msg->body.finished.seq = body.finished.seq; + msg->body.finished.handled = body.finished.handled; + break; + } + default: { + LOG_FATAL("Unexpected message type %i", header.type); + break; + } + } +} // --- InputChannel --- @@ -150,10 +246,12 @@ status_t InputChannel::openInputChannelPair(const String8& name, } status_t InputChannel::sendMessage(const InputMessage* msg) { - size_t msgLength = msg->size(); + const size_t msgLength = msg->size(); + InputMessage cleanMsg; + msg->getSanitizedCopy(&cleanMsg); ssize_t nWrite; do { - nWrite = ::send(mFd, msg, msgLength, MSG_DONTWAIT | MSG_NOSIGNAL); + nWrite = ::send(mFd, &cleanMsg, msgLength, MSG_DONTWAIT | MSG_NOSIGNAL); } while (nWrite == -1 && errno == EINTR); if (nWrite < 0) { diff --git a/libs/input/tests/StructLayout_test.cpp b/libs/input/tests/StructLayout_test.cpp index 8d73f453e0..5172681e3b 100644 --- a/libs/input/tests/StructLayout_test.cpp +++ b/libs/input/tests/StructLayout_test.cpp @@ -63,6 +63,9 @@ void TestInputMessageAlignment() { CHECK_OFFSET(InputMessage::Body::Motion, yPrecision, 68); CHECK_OFFSET(InputMessage::Body::Motion, pointerCount, 72); CHECK_OFFSET(InputMessage::Body::Motion, pointers, 80); + + CHECK_OFFSET(InputMessage::Body::Finished, seq, 0); + CHECK_OFFSET(InputMessage::Body::Finished, handled, 4); } } // namespace android -- cgit v1.2.3-59-g8ed1b From e730f5aaa1c726ee9998a080e2d7f6284f4afec8 Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Fri, 16 Nov 2018 22:18:53 -0800 Subject: Sanitize InputMessage before sending The struct InputMessage has many fields, and is force-aligned to 8-byte boundaries. There are also some padding fields that carry no information. This struct is typically allocated in the stack and populated with various values before being sent across as a stream of bytes through the socket. Therefore, the "unused" data portions of the struct could contain portions of the stack, since there aren't ever writes to those memory locations. To avoid this information leak, forcefully sanitize the struct. Create a new struct that is explicitly set to zero. Next, only fill the meaningful fields manually. Bug: 115739809 Test: cts-tradefed run cts -m CtsSecurityBulletinHostTestCases -t android.security.cts.Poc18_12; adb shell monkey 100000 Change-Id: I7e44dacf1e8fa3156c8e4d2f7784ef0c53dab507 Merged-In: I7e44dacf1e8fa3156c8e4d2f7784ef0c53dab507 --- include/input/InputTransport.h | 13 ++++ libs/input/InputTransport.cpp | 106 ++++++++++++++++++++++++++++++++- libs/input/tests/StructLayout_test.cpp | 3 + 3 files changed, 120 insertions(+), 2 deletions(-) diff --git a/include/input/InputTransport.h b/include/input/InputTransport.h index ea1d2aa41f..9f3d45a3bc 100644 --- a/include/input/InputTransport.h +++ b/include/input/InputTransport.h @@ -42,6 +42,13 @@ namespace android { * * Note that this structure is used for IPCs so its layout must be identical * on 64 and 32 bit processes. This is tested in StructLayout_test.cpp. + * + * Since the struct must be aligned to an 8-byte boundary, there could be uninitialized bytes + * in-between the defined fields. This padding data should be explicitly accounted for by adding + * "empty" fields into the struct. This data is memset to zero before sending the struct across + * the socket. Adding the explicit fields ensures that the memset is not optimized away by the + * compiler. When a new field is added to the struct, the corresponding change + * in StructLayout_test should be made. */ struct InputMessage { enum { @@ -62,6 +69,7 @@ struct InputMessage { union Body { struct Key { uint32_t seq; + uint32_t empty1; nsecs_t eventTime __attribute__((aligned(8))); int32_t deviceId; int32_t source; @@ -72,6 +80,7 @@ struct InputMessage { int32_t scanCode; int32_t metaState; int32_t repeatCount; + uint32_t empty2; nsecs_t downTime __attribute__((aligned(8))); inline size_t size() const { @@ -81,6 +90,7 @@ struct InputMessage { struct Motion { uint32_t seq; + uint32_t empty1; nsecs_t eventTime __attribute__((aligned(8))); int32_t deviceId; int32_t source; @@ -91,12 +101,14 @@ struct InputMessage { int32_t metaState; int32_t buttonState; int32_t edgeFlags; + uint32_t empty2; nsecs_t downTime __attribute__((aligned(8))); float xOffset; float yOffset; float xPrecision; float yPrecision; uint32_t pointerCount; + uint32_t empty3; // Note that PointerCoords requires 8 byte alignment. struct Pointer { PointerProperties properties; @@ -127,6 +139,7 @@ struct InputMessage { bool isValid(size_t actualSize) const; size_t size() const; + void getSanitizedCopy(InputMessage* msg) const; }; /* diff --git a/libs/input/InputTransport.cpp b/libs/input/InputTransport.cpp index 3e8b67931a..1918379777 100644 --- a/libs/input/InputTransport.cpp +++ b/libs/input/InputTransport.cpp @@ -96,6 +96,106 @@ size_t InputMessage::size() const { return sizeof(Header); } +/** + * There could be non-zero bytes in-between InputMessage fields. Force-initialize the entire + * memory to zero, then only copy the valid bytes on a per-field basis. + */ +void InputMessage::getSanitizedCopy(InputMessage* msg) const { + memset(msg, 0, sizeof(*msg)); + + // Write the header + msg->header.type = header.type; + + // Write the body + switch(header.type) { + case InputMessage::TYPE_KEY: { + // uint32_t seq + msg->body.key.seq = body.key.seq; + // nsecs_t eventTime + msg->body.key.eventTime = body.key.eventTime; + // int32_t deviceId + msg->body.key.deviceId = body.key.deviceId; + // int32_t source + msg->body.key.source = body.key.source; + // int32_t displayId + msg->body.key.displayId = body.key.displayId; + // int32_t action + msg->body.key.action = body.key.action; + // int32_t flags + msg->body.key.flags = body.key.flags; + // int32_t keyCode + msg->body.key.keyCode = body.key.keyCode; + // int32_t scanCode + msg->body.key.scanCode = body.key.scanCode; + // int32_t metaState + msg->body.key.metaState = body.key.metaState; + // int32_t repeatCount + msg->body.key.repeatCount = body.key.repeatCount; + // nsecs_t downTime + msg->body.key.downTime = body.key.downTime; + break; + } + case InputMessage::TYPE_MOTION: { + // uint32_t seq + msg->body.motion.seq = body.motion.seq; + // nsecs_t eventTime + msg->body.motion.eventTime = body.motion.eventTime; + // int32_t deviceId + msg->body.motion.deviceId = body.motion.deviceId; + // int32_t source + msg->body.motion.source = body.motion.source; + // int32_t displayId + msg->body.motion.displayId = body.motion.displayId; + // int32_t action + msg->body.motion.action = body.motion.action; + // int32_t actionButton + msg->body.motion.actionButton = body.motion.actionButton; + // int32_t flags + msg->body.motion.flags = body.motion.flags; + // int32_t metaState + msg->body.motion.metaState = body.motion.metaState; + // int32_t buttonState + msg->body.motion.buttonState = body.motion.buttonState; + // int32_t edgeFlags + msg->body.motion.edgeFlags = body.motion.edgeFlags; + // nsecs_t downTime + msg->body.motion.downTime = body.motion.downTime; + // float xOffset + msg->body.motion.xOffset = body.motion.xOffset; + // float yOffset + msg->body.motion.yOffset = body.motion.yOffset; + // float xPrecision + msg->body.motion.xPrecision = body.motion.xPrecision; + // float yPrecision + msg->body.motion.yPrecision = body.motion.yPrecision; + // uint32_t pointerCount + msg->body.motion.pointerCount = body.motion.pointerCount; + //struct Pointer pointers[MAX_POINTERS] + for (size_t i = 0; i < body.motion.pointerCount; i++) { + // PointerProperties properties + msg->body.motion.pointers[i].properties.id = body.motion.pointers[i].properties.id; + msg->body.motion.pointers[i].properties.toolType = + body.motion.pointers[i].properties.toolType, + // PointerCoords coords + msg->body.motion.pointers[i].coords.bits = body.motion.pointers[i].coords.bits; + const uint32_t count = BitSet64::count(body.motion.pointers[i].coords.bits); + memcpy(&msg->body.motion.pointers[i].coords.values[0], + &body.motion.pointers[i].coords.values[0], + count * (sizeof(body.motion.pointers[i].coords.values[0]))); + } + break; + } + case InputMessage::TYPE_FINISHED: { + msg->body.finished.seq = body.finished.seq; + msg->body.finished.handled = body.finished.handled; + break; + } + default: { + LOG_FATAL("Unexpected message type %i", header.type); + break; + } + } +} // --- InputChannel --- @@ -149,10 +249,12 @@ status_t InputChannel::openInputChannelPair(const String8& name, } status_t InputChannel::sendMessage(const InputMessage* msg) { - size_t msgLength = msg->size(); + const size_t msgLength = msg->size(); + InputMessage cleanMsg; + msg->getSanitizedCopy(&cleanMsg); ssize_t nWrite; do { - nWrite = ::send(mFd, msg, msgLength, MSG_DONTWAIT | MSG_NOSIGNAL); + nWrite = ::send(mFd, &cleanMsg, msgLength, MSG_DONTWAIT | MSG_NOSIGNAL); } while (nWrite == -1 && errno == EINTR); if (nWrite < 0) { diff --git a/libs/input/tests/StructLayout_test.cpp b/libs/input/tests/StructLayout_test.cpp index d19f3b8066..12a67828ac 100644 --- a/libs/input/tests/StructLayout_test.cpp +++ b/libs/input/tests/StructLayout_test.cpp @@ -65,6 +65,9 @@ void TestInputMessageAlignment() { CHECK_OFFSET(InputMessage::Body::Motion, yPrecision, 76); CHECK_OFFSET(InputMessage::Body::Motion, pointerCount, 80); CHECK_OFFSET(InputMessage::Body::Motion, pointers, 88); + + CHECK_OFFSET(InputMessage::Body::Finished, seq, 0); + CHECK_OFFSET(InputMessage::Body::Finished, handled, 4); } } // namespace android -- cgit v1.2.3-59-g8ed1b From ac1f7c9c50b468315dbd4b0e71e03fb736fd98eb Mon Sep 17 00:00:00 2001 From: Siddharth Kapoor Date: Wed, 5 Dec 2018 20:29:06 +0800 Subject: [RenderEngine] Clamp input color for BT2020_PQ EOTF Color input to EOTF for PQ transfer function is out-of-bounds [0.0, 1.0] Reason being, texture2D returns values which is not in range [0.0, 1.0]. These returned values are passed as gl_FragColor.rgb to EOTF for PQ transfer function. In EOTF, colors outside the range [0.0, 1.0] are rendered as black resulting in artifacts while video playback. Clamp the input color to the range [0.0, 1.0] Bug: 118794307 Test: Youtube HDR video plays fine, also screenshots taken while playback does not have any artifacts. Change-Id: I266f5a009c4c58924510283295757abae811a41e --- services/surfaceflinger/RenderEngine/ProgramCache.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/surfaceflinger/RenderEngine/ProgramCache.cpp b/services/surfaceflinger/RenderEngine/ProgramCache.cpp index 9dc6858566..46402d5164 100644 --- a/services/surfaceflinger/RenderEngine/ProgramCache.cpp +++ b/services/surfaceflinger/RenderEngine/ProgramCache.cpp @@ -220,7 +220,7 @@ void ProgramCache::generateEOTF(Formatter& fs, const Key& needs) { const highp float c2 = (2413.0 / 4096.0) * 32.0; const highp float c3 = (2392.0 / 4096.0) * 32.0; - highp vec3 tmp = pow(color, 1.0 / vec3(m2)); + highp vec3 tmp = pow(clamp(color, 0.0, 1.0), 1.0 / vec3(m2)); tmp = max(tmp - c1, 0.0) / (c2 - c3 * tmp); return pow(tmp, 1.0 / vec3(m1)); } -- cgit v1.2.3-59-g8ed1b