Skip to content

Commit

Permalink
cupidr: sensors: Adapt to Android 14
Browse files Browse the repository at this point in the history
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
  • Loading branch information
xdevs23 authored and pjgowtham committed Jan 1, 2024
1 parent f86f07e commit 70232fd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
12 changes: 10 additions & 2 deletions sensors/als_correction_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<IBinder> getInternalDisplayToken() {
const auto displayIds = SurfaceComposerClient::getPhysicalDisplayIds();
sp<IBinder> token = SurfaceComposerClient::getPhysicalDisplayToken(displayIds[0]);
return token;
}

void updateScreenBuffer() {
static time_t lastScreenUpdate = 0;
static sp<GraphicBuffer> outBuffer = new GraphicBuffer(
Expand All @@ -59,10 +67,10 @@ void updateScreenBuffer() {
return;
}

sp<IBinder> display = SurfaceComposerClient::getInternalDisplayToken();
sp<IBinder> 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,
Expand Down
7 changes: 5 additions & 2 deletions sensors/include/AsyncScreenCaptureListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit 70232fd

Please sign in to comment.