From 143761017c79c39ba3af053a7b42f196fe5ffa7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sim=C3=A3o=20Gomes=20Viana?= Date: Mon, 9 Oct 2023 00:18:17 +0200 Subject: [PATCH] cupidr: sensors: Adapt to Android 14 getInternalDisplayToken was removed from Android U, so we need to do things it was doing ourselves. Additionally, the field fence does not longer exist in ScreenCaptureResult so instead we need to use the replacement. Change-Id: I7ff6efe8d328785d211ebd8b2ea3c7d3fcd482fc --- sensors/als_correction_service.cpp | 12 ++++++++++-- sensors/include/AsyncScreenCaptureListener.h | 7 +++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/sensors/als_correction_service.cpp b/sensors/als_correction_service.cpp index 1f07b7f..59610fc 100644 --- a/sensors/als_correction_service.cpp +++ b/sensors/als_correction_service.cpp @@ -45,6 +45,14 @@ constexpr int ALS_POS_Y = 40; constexpr int ALS_RADIUS = 64; constexpr int SCREENSHOT_INTERVAL = 1; +// See frameworks/base/services/core/jni/com_android_server_display_DisplayControl.cpp and +// frameworks/base/core/java/android/view/SurfaceControl.java +static sp getInternalDisplayToken() { + const auto displayIds = SurfaceComposerClient::getPhysicalDisplayIds(); + sp token = SurfaceComposerClient::getPhysicalDisplayToken(displayIds[0]); + return token; +} + void updateScreenBuffer() { static time_t lastScreenUpdate = 0; static sp outBuffer = new GraphicBuffer( @@ -59,10 +67,10 @@ void updateScreenBuffer() { return; } - sp display = SurfaceComposerClient::getInternalDisplayToken(); + sp display = getInternalDisplayToken(); DisplayCaptureArgs captureArgs; - captureArgs.displayToken = SurfaceComposerClient::getInternalDisplayToken(); + captureArgs.displayToken = getInternalDisplayToken(); captureArgs.pixelFormat = PixelFormat::RGBA_8888; captureArgs.sourceCrop = Rect( ALS_POS_X - ALS_RADIUS, ALS_POS_Y - ALS_RADIUS, diff --git a/sensors/include/AsyncScreenCaptureListener.h b/sensors/include/AsyncScreenCaptureListener.h index e483416..29bee4d 100644 --- a/sensors/include/AsyncScreenCaptureListener.h +++ b/sensors/include/AsyncScreenCaptureListener.h @@ -31,8 +31,11 @@ struct AsyncScreenCaptureListener : gui::BnScreenCaptureListener { : callback(callback), timeout(timeout) {} binder::Status onScreenCaptureCompleted(const ScreenCaptureResults& captureResults) override { - if (captureResults.fence->wait(timeout) == NO_ERROR) - callback(captureResults); + if (captureResults.fenceResult.ok()) { + if (captureResults.fenceResult.value()->wait(timeout) == OK) { + callback(captureResults); + } + } return binder::Status::ok(); }