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