Merge "vulkan: update Vulkan headers to 1.0.46" into oc-dev
diff --git a/cmds/servicemanager/Android.bp b/cmds/servicemanager/Android.bp
index 5431233..68d39db 100644
--- a/cmds/servicemanager/Android.bp
+++ b/cmds/servicemanager/Android.bp
@@ -43,6 +43,9 @@
"service_manager.c",
"binder.c",
],
+ cflags: [
+ "-DVENDORSERVICEMANAGER=1",
+ ],
shared_libs: ["libcutils", "libselinux"],
init_rc: ["vndservicemanager.rc"],
}
diff --git a/cmds/servicemanager/service_manager.c b/cmds/servicemanager/service_manager.c
index 5d44e87..45bb1d0 100644
--- a/cmds/servicemanager/service_manager.c
+++ b/cmds/servicemanager/service_manager.c
@@ -17,13 +17,12 @@
#include "binder.h"
-#if 0
-#define ALOGI(x...) fprintf(stderr, "svcmgr: " x)
-#define ALOGE(x...) fprintf(stderr, "svcmgr: " x)
+#ifdef VENDORSERVICEMANAGER
+#define LOG_TAG "VendorServiceManager"
#else
#define LOG_TAG "ServiceManager"
-#include <log/log.h>
#endif
+#include <log/log.h>
struct audit_data {
pid_t pid;
@@ -374,7 +373,14 @@
bs = binder_open(driver, 128*1024);
if (!bs) {
+#ifdef VENDORSERVICEMANAGER
+ ALOGW("failed to open binder driver %s\n", driver);
+ while (true) {
+ sleep(UINT_MAX);
+ }
+#else
ALOGE("failed to open binder driver %s\n", driver);
+#endif
return -1;
}
@@ -388,7 +394,11 @@
cb.func_log = selinux_log_callback;
selinux_set_callback(SELINUX_CB_LOG, cb);
+#ifdef VENDORSERVICEMANAGER
+ sehandle = selinux_android_vendor_service_context_handle();
+#else
sehandle = selinux_android_service_context_handle();
+#endif
selinux_status_open(true);
if (sehandle == NULL) {
diff --git a/cmds/servicemanager/servicemanager.rc b/cmds/servicemanager/servicemanager.rc
index aee7bd8..aec211a 100644
--- a/cmds/servicemanager/servicemanager.rc
+++ b/cmds/servicemanager/servicemanager.rc
@@ -1,5 +1,5 @@
service servicemanager /system/bin/servicemanager
- class core
+ class core animation
user system
group system readproc
critical
@@ -12,4 +12,3 @@
onrestart restart drm
onrestart restart cameraserver
writepid /dev/cpuset/system-background/tasks
-
diff --git a/include/android/native_window_jni.h b/include/android/native_window_jni.h
index 1ec2a67..23b39aa 100644
--- a/include/android/native_window_jni.h
+++ b/include/android/native_window_jni.h
@@ -54,6 +54,17 @@
ANativeWindow* ANativeWindow_fromSurfaceTexture(JNIEnv* env, jobject surfaceTexture);
#endif
+#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
+ * the ANativeWindow; maintains it through general Java object's life cycle;
+ * and will automatically release the reference when the Java object gets garbage
+ * collected.
+ */
+jobject ANativeWindow_toSurface(JNIEnv* env, ANativeWindow* window);
+#endif
+
#ifdef __cplusplus
};
#endif
diff --git a/include/gui/Surface.h b/include/gui/Surface.h
index 62f6cad..88ef010 100644
--- a/include/gui/Surface.h
+++ b/include/gui/Surface.h
@@ -257,10 +257,25 @@
virtual int query(int what, int* value) const;
virtual int connect(int api, const sp<IProducerListener>& listener);
+
+ // When reportBufferRemoval is true, clients must call getAndFlushRemovedBuffers to fetch
+ // GraphicBuffers removed from this surface after a dequeueBuffer, detachNextBuffer or
+ // attachBuffer call. This allows clients with their own buffer caches to free up buffers no
+ // longer in use by this surface.
+ virtual int connect(
+ int api, const sp<IProducerListener>& listener,
+ bool reportBufferRemoval);
virtual int detachNextBuffer(sp<GraphicBuffer>* outBuffer,
sp<Fence>* outFence);
virtual int attachBuffer(ANativeWindowBuffer*);
+ // When client connects to Surface with reportBufferRemoval set to true, any buffers removed
+ // from this Surface will be collected and returned here. Once this method returns, these
+ // buffers will no longer be referenced by this Surface unless they are attached to this
+ // Surface later. The list of removed buffers will only be stored until the next dequeueBuffer,
+ // detachNextBuffer, or attachBuffer call.
+ status_t getAndFlushRemovedBuffers(std::vector<sp<GraphicBuffer>>* out);
+
protected:
enum { NUM_BUFFER_SLOTS = BufferQueueDefs::NUM_BUFFER_SLOTS };
enum { DEFAULT_FORMAT = PIXEL_FORMAT_RGBA_8888 };
@@ -414,6 +429,9 @@
// A cached copy of the FrameEventHistory maintained by the consumer.
bool mEnableFrameTimestamps = false;
std::unique_ptr<ProducerFrameEventHistory> mFrameEventHistory;
+
+ bool mReportRemovedBuffers = false;
+ std::vector<sp<GraphicBuffer>> mRemovedBuffers;
};
} // namespace android
diff --git a/include/ui/GraphicBuffer.h b/include/ui/GraphicBuffer.h
index 040d1e7..33ec4bb 100644
--- a/include/ui/GraphicBuffer.h
+++ b/include/ui/GraphicBuffer.h
@@ -72,27 +72,66 @@
USAGE_CURSOR = GRALLOC_USAGE_CURSOR,
};
+ // Create a GraphicBuffer to be unflatten'ed into or be reallocated.
GraphicBuffer();
- // creates w * h buffer
- GraphicBuffer(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat,
- uint32_t inUsage, std::string requestorName = "<Unknown>");
-
- // creates w * h buffer with a layer count using gralloc1
+ // Create a GraphicBuffer by allocating and managing a buffer internally.
+ // This function is privileged. See reallocate for details.
GraphicBuffer(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat,
uint32_t inLayerCount, uint64_t inProducerUsage,
uint64_t inConsumerUsage, std::string requestorName = "<Unknown>");
- // create a buffer from an existing handle
+ // Create a GraphicBuffer from an existing handle.
+ enum HandleWrapMethod : uint8_t {
+ // Wrap and use the handle directly. It assumes the handle has been
+ // registered and never fails. The handle must have a longer lifetime
+ // than this wrapping GraphicBuffer.
+ //
+ // This can be used when, for example, you want to wrap a handle that
+ // is already managed by another GraphicBuffer.
+ WRAP_HANDLE,
+
+ // Take ownership of the handle and use it directly. It assumes the
+ // handle has been registered and never fails.
+ //
+ // This can be used to manage an already registered handle with
+ // GraphicBuffer.
+ TAKE_HANDLE,
+
+ // Take onwership of an unregistered handle and use it directly. It
+ // can fail when the buffer does not register. There is no ownership
+ // transfer on failures.
+ //
+ // This can be used to, for example, create a GraphicBuffer from a
+ // handle returned by Parcel::readNativeHandle.
+ TAKE_UNREGISTERED_HANDLE,
+
+ // Make a clone of the handle and use the cloned handle. It can fail
+ // when cloning fails or when the buffer does not register. There is
+ // never ownership transfer.
+ //
+ // This can be used to create a GraphicBuffer from a handle that
+ // cannot be used directly, such as one from hidl_handle.
+ CLONE_HANDLE,
+ };
+ GraphicBuffer(const native_handle_t* handle, HandleWrapMethod method,
+ uint32_t width, uint32_t height,
+ PixelFormat format, uint32_t layerCount,
+ uint64_t producerUsage, uint64_t consumerUsage, uint32_t stride);
+
+ // These functions are deprecated because they do not distinguish producer
+ // and consumer usages.
+ GraphicBuffer(const native_handle_t* handle, HandleWrapMethod method,
+ uint32_t width, uint32_t height,
+ PixelFormat format, uint32_t layerCount,
+ uint32_t usage, uint32_t stride)
+ : GraphicBuffer(handle, method, width, height, format, layerCount,
+ usage, usage, stride) {}
GraphicBuffer(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat,
uint32_t inLayerCount, uint32_t inUsage, uint32_t inStride,
native_handle_t* inHandle, bool keepOwnership);
-
- // create a buffer from an existing handle using gralloc1
GraphicBuffer(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat,
- uint32_t inLayerCount, uint32_t inProducerUsage,
- uint32_t inConsumerUsage, uint32_t inStride,
- native_handle_t* inHandle, bool keepOwnership);
+ uint32_t inUsage, std::string requestorName = "<Unknown>");
// create a buffer from an existing ANativeWindowBuffer
GraphicBuffer(ANativeWindowBuffer* buffer, bool keepOwnership);
@@ -114,6 +153,9 @@
mGenerationNumber = generation;
}
+ // This function is privileged. It requires access to the allocator
+ // device or service, which usually involves adding suitable selinux
+ // rules.
status_t reallocate(uint32_t inWidth, uint32_t inHeight,
PixelFormat inFormat, uint32_t inLayerCount, uint32_t inUsage);
@@ -175,9 +217,15 @@
GraphicBuffer& operator = (const GraphicBuffer& rhs);
const GraphicBuffer& operator = (const GraphicBuffer& rhs) const;
- status_t initSize(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat,
- uint32_t inLayerCount, uint64_t inProducerUsage,
- uint64_t inConsumerUsage, std::string requestorName);
+ status_t initWithSize(uint32_t inWidth, uint32_t inHeight,
+ PixelFormat inFormat, uint32_t inLayerCount,
+ uint64_t inProducerUsage, uint64_t inConsumerUsage,
+ std::string requestorName);
+
+ status_t initWithHandle(const native_handle_t* handle,
+ HandleWrapMethod method, uint32_t width, uint32_t height,
+ PixelFormat format, uint32_t layerCount,
+ uint64_t producerUsage, uint64_t consumerUsage, uint32_t stride);
void free_handle();
diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp
index 06fc31d..1149b89 100644
--- a/libs/gui/Surface.cpp
+++ b/libs/gui/Surface.cpp
@@ -505,7 +505,11 @@
mFrameEventHistory->applyDelta(frameTimestamps);
}
- if ((result & IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION) || gbuf == 0) {
+ if ((result & IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION) || gbuf == nullptr) {
+ if (mReportRemovedBuffers && (gbuf != nullptr)) {
+ mRemovedBuffers.clear();
+ mRemovedBuffers.push_back(gbuf);
+ }
result = mGraphicBufferProducer->requestBuffer(buf, &gbuf);
if (result != NO_ERROR) {
ALOGE("dequeueBuffer: IGraphicBufferProducer::requestBuffer failed: %d", result);
@@ -1075,10 +1079,16 @@
}
int Surface::connect(int api, const sp<IProducerListener>& listener) {
+ return connect(api, listener, false);
+}
+
+int Surface::connect(
+ int api, const sp<IProducerListener>& listener, bool reportBufferRemoval) {
ATRACE_CALL();
ALOGV("Surface::connect");
Mutex::Autolock lock(mMutex);
IGraphicBufferProducer::QueueBufferOutput output;
+ mReportRemovedBuffers = reportBufferRemoval;
int err = mGraphicBufferProducer->connect(listener, api, mProducerControlledByApp, &output);
if (err == NO_ERROR) {
mDefaultWidth = output.width;
@@ -1109,6 +1119,7 @@
ATRACE_CALL();
ALOGV("Surface::disconnect");
Mutex::Autolock lock(mMutex);
+ mRemovedBuffers.clear();
mSharedBufferSlot = BufferItem::INVALID_BUFFER_SLOT;
mSharedBufferHasBeenQueued = false;
freeAllBuffers();
@@ -1156,9 +1167,16 @@
*outFence = Fence::NO_FENCE;
}
+ if (mReportRemovedBuffers) {
+ mRemovedBuffers.clear();
+ }
+
for (int i = 0; i < NUM_BUFFER_SLOTS; i++) {
if (mSlots[i].buffer != NULL &&
mSlots[i].buffer->handle == buffer->handle) {
+ if (mReportRemovedBuffers) {
+ mRemovedBuffers.push_back(mSlots[i].buffer);
+ }
mSlots[i].buffer = NULL;
}
}
@@ -1184,6 +1202,10 @@
graphicBuffer->mGenerationNumber = priorGeneration;
return result;
}
+ if (mReportRemovedBuffers && (mSlots[attachedSlot].buffer != nullptr)) {
+ mRemovedBuffers.clear();
+ mRemovedBuffers.push_back(mSlots[attachedSlot].buffer);
+ }
mSlots[attachedSlot].buffer = graphicBuffer;
return NO_ERROR;
@@ -1617,4 +1639,16 @@
return mGraphicBufferProducer->getUniqueId(outId);
}
+status_t Surface::getAndFlushRemovedBuffers(std::vector<sp<GraphicBuffer>>* out) {
+ if (out == nullptr) {
+ ALOGE("%s: out must not be null!", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ Mutex::Autolock lock(mMutex);
+ *out = mRemovedBuffers;
+ mRemovedBuffers.clear();
+ return OK;
+}
+
}; // namespace android
diff --git a/libs/nativewindow/AHardwareBuffer.cpp b/libs/nativewindow/AHardwareBuffer.cpp
index 1ed150b..a38b4dc 100644
--- a/libs/nativewindow/AHardwareBuffer.cpp
+++ b/libs/nativewindow/AHardwareBuffer.cpp
@@ -28,6 +28,7 @@
#include <ui/GraphicBuffer.h>
#include <system/graphics.h>
#include <hardware/gralloc1.h>
+#include <grallocusage/GrallocUsageConversion.h>
#include <private/android/AHardwareBufferHelpers.h>
@@ -100,8 +101,12 @@
outDesc->width = gbuffer->getWidth();
outDesc->height = gbuffer->getHeight();
outDesc->layers = gbuffer->getLayerCount();
+
+ uint64_t producerUsage = 0;
+ uint64_t consumerUsage = 0;
+ android_convertGralloc0To1Usage(gbuffer->getUsage(), &producerUsage, &consumerUsage);
AHardwareBuffer_convertFromGrallocUsageBits(&outDesc->usage0, &outDesc->usage1,
- gbuffer->getUsage(), gbuffer->getUsage());
+ producerUsage, consumerUsage);
outDesc->format = AHardwareBuffer_convertFromPixelFormat(
static_cast<uint32_t>(gbuffer->getPixelFormat()));
}
diff --git a/libs/nativewindow/ANativeWindow.cpp b/libs/nativewindow/ANativeWindow.cpp
index c0c4ac0..6c67cf8 100644
--- a/libs/nativewindow/ANativeWindow.cpp
+++ b/libs/nativewindow/ANativeWindow.cpp
@@ -25,6 +25,8 @@
#include <private/android/AHardwareBufferHelpers.h>
+#include <ui/GraphicBuffer.h>
+
using namespace android;
static int32_t query(ANativeWindow* window, int what) {
@@ -105,6 +107,10 @@
* vndk-stable
**************************************************************************************************/
+AHardwareBuffer* ANativeWindowBuffer_getHardwareBuffer(ANativeWindowBuffer* anwb) {
+ return AHardwareBuffer_from_GraphicBuffer(static_cast<GraphicBuffer*>(anwb));
+}
+
int ANativeWindow_OemStorageSet(ANativeWindow* window, uint32_t slot, intptr_t value) {
if (slot < 4) {
window->oem[slot] = value;
diff --git a/libs/nativewindow/include/vndk/window.h b/libs/nativewindow/include/vndk/window.h
index 310e1e5..067046b 100644
--- a/libs/nativewindow/include/vndk/window.h
+++ b/libs/nativewindow/include/vndk/window.h
@@ -99,8 +99,12 @@
typedef struct ANativeWindowBuffer ANativeWindowBuffer;
-/*****************************************************************************/
+/*
+ * Convert this ANativeWindowBuffer into a AHardwareBuffer
+ */
+AHardwareBuffer* ANativeWindowBuffer_getHardwareBuffer(ANativeWindowBuffer* anwb);
+/*****************************************************************************/
/*
* Stores a value into one of the 4 available slots
diff --git a/libs/sensor/include/sensor/SensorEventQueue.h b/libs/sensor/include/sensor/SensorEventQueue.h
index a03c7ee..baed2ee 100644
--- a/libs/sensor/include/sensor/SensorEventQueue.h
+++ b/libs/sensor/include/sensor/SensorEventQueue.h
@@ -83,7 +83,7 @@
status_t disableSensor(Sensor const* sensor) const;
status_t setEventRate(Sensor const* sensor, nsecs_t ns) const;
- // these are here only to support SensorManager.java
+ // these are here only to support SensorManager.java and HIDL Frameworks SensorManager.
status_t enableSensor(int32_t handle, int32_t samplingPeriodUs, int64_t maxBatchReportLatencyUs,
int reservedFlags) const;
status_t disableSensor(int32_t handle) const;
diff --git a/libs/ui/GraphicBuffer.cpp b/libs/ui/GraphicBuffer.cpp
index 6e84730..4fae233 100644
--- a/libs/ui/GraphicBuffer.cpp
+++ b/libs/ui/GraphicBuffer.cpp
@@ -52,73 +52,33 @@
handle = NULL;
}
+// deprecated
GraphicBuffer::GraphicBuffer(uint32_t inWidth, uint32_t inHeight,
PixelFormat inFormat, uint32_t inUsage, std::string requestorName)
- : BASE(), mOwner(ownData), mBufferMapper(GraphicBufferMapper::get()),
- mInitCheck(NO_ERROR), mId(getUniqueId()), mGenerationNumber(0)
+ : GraphicBuffer(inWidth, inHeight, inFormat, 1, inUsage, inUsage,
+ requestorName)
{
- width =
- height =
- stride =
- format =
- usage = 0;
- layerCount = 0;
- handle = NULL;
- mInitCheck = initSize(inWidth, inHeight, inFormat, 1, inUsage, inUsage,
- std::move(requestorName));
}
GraphicBuffer::GraphicBuffer(uint32_t inWidth, uint32_t inHeight,
PixelFormat inFormat, uint32_t inLayerCount, uint64_t producerUsage,
uint64_t consumerUsage, std::string requestorName)
- : BASE(), mOwner(ownData), mBufferMapper(GraphicBufferMapper::get()),
- mInitCheck(NO_ERROR), mId(getUniqueId()), mGenerationNumber(0)
+ : GraphicBuffer()
{
- width =
- height =
- stride =
- format =
- usage = 0;
- layerCount = 0;
- handle = NULL;
- mInitCheck = initSize(inWidth, inHeight, inFormat, inLayerCount,
+ mInitCheck = initWithSize(inWidth, inHeight, inFormat, inLayerCount,
producerUsage, consumerUsage, std::move(requestorName));
}
+// deprecated
GraphicBuffer::GraphicBuffer(uint32_t inWidth, uint32_t inHeight,
PixelFormat inFormat, uint32_t inLayerCount, uint32_t inUsage,
uint32_t inStride, native_handle_t* inHandle, bool keepOwnership)
- : BASE(), mOwner(keepOwnership ? ownHandle : ownNone),
- mBufferMapper(GraphicBufferMapper::get()),
- mInitCheck(NO_ERROR), mId(getUniqueId()), mGenerationNumber(0)
+ : GraphicBuffer(inHandle, keepOwnership ? TAKE_HANDLE : WRAP_HANDLE,
+ inWidth, inHeight, inFormat, inLayerCount, inUsage, inUsage,
+ inStride)
{
- width = static_cast<int>(inWidth);
- height = static_cast<int>(inHeight);
- stride = static_cast<int>(inStride);
- format = inFormat;
- layerCount = inLayerCount;
- usage = static_cast<int>(inUsage);
- handle = inHandle;
}
-GraphicBuffer::GraphicBuffer(uint32_t inWidth, uint32_t inHeight,
- PixelFormat inFormat, uint32_t inLayerCount, uint32_t inProducerUsage,
- uint32_t inConsumerUsage, uint32_t inStride,
- native_handle_t* inHandle, bool keepOwnership)
- : BASE(), mOwner(keepOwnership ? ownHandle : ownNone),
- mBufferMapper(GraphicBufferMapper::get()),
- mInitCheck(NO_ERROR), mId(getUniqueId()), mGenerationNumber(0)
-{
- width = static_cast<int>(inWidth);
- height = static_cast<int>(inHeight);
- stride = static_cast<int>(inStride);
- format = inFormat;
- layerCount = inLayerCount;
- usage = android_convertGralloc1To0Usage(inProducerUsage, inConsumerUsage);
- handle = inHandle;
-}
-
-
GraphicBuffer::GraphicBuffer(ANativeWindowBuffer* buffer, bool keepOwnership)
: BASE(), mOwner(keepOwnership ? ownHandle : ownNone),
mBufferMapper(GraphicBufferMapper::get()),
@@ -134,6 +94,17 @@
handle = buffer->handle;
}
+GraphicBuffer::GraphicBuffer(const native_handle_t* handle,
+ HandleWrapMethod method, uint32_t width, uint32_t height,
+ PixelFormat format, uint32_t layerCount,
+ uint64_t producerUsage, uint64_t consumerUsage,
+ uint32_t stride)
+ : GraphicBuffer()
+{
+ mInitCheck = initWithHandle(handle, method, width, height, format,
+ layerCount, producerUsage, consumerUsage, stride);
+}
+
GraphicBuffer::~GraphicBuffer()
{
if (handle) {
@@ -192,8 +163,8 @@
allocator.free(handle);
handle = 0;
}
- return initSize(inWidth, inHeight, inFormat, inLayerCount, inUsage, inUsage,
- "[Reallocation]");
+ return initWithSize(inWidth, inHeight, inFormat, inLayerCount,
+ inUsage, inUsage, "[Reallocation]");
}
bool GraphicBuffer::needsReallocation(uint32_t inWidth, uint32_t inHeight,
@@ -207,7 +178,7 @@
return false;
}
-status_t GraphicBuffer::initSize(uint32_t inWidth, uint32_t inHeight,
+status_t GraphicBuffer::initWithSize(uint32_t inWidth, uint32_t inHeight,
PixelFormat inFormat, uint32_t inLayerCount, uint64_t inProducerUsage,
uint64_t inConsumerUsage, std::string requestorName)
{
@@ -227,6 +198,54 @@
return err;
}
+status_t GraphicBuffer::initWithHandle(const native_handle_t* handle,
+ HandleWrapMethod method, uint32_t width, uint32_t height,
+ PixelFormat format, uint32_t layerCount,
+ uint64_t producerUsage, uint64_t consumerUsage,
+ uint32_t stride)
+{
+ native_handle_t* clone = nullptr;
+
+ if (method == CLONE_HANDLE) {
+ clone = native_handle_clone(handle);
+ if (!clone) {
+ return NO_MEMORY;
+ }
+
+ handle = clone;
+ method = TAKE_UNREGISTERED_HANDLE;
+ }
+
+ ANativeWindowBuffer::width = static_cast<int>(width);
+ ANativeWindowBuffer::height = static_cast<int>(height);
+ ANativeWindowBuffer::stride = static_cast<int>(stride);
+ ANativeWindowBuffer::format = format;
+ ANativeWindowBuffer::usage =
+ android_convertGralloc1To0Usage(producerUsage, consumerUsage);
+
+ ANativeWindowBuffer::layerCount = layerCount;
+ ANativeWindowBuffer::handle = handle;
+
+ mOwner = (method == WRAP_HANDLE) ? ownNone : ownHandle;
+
+ if (method == TAKE_UNREGISTERED_HANDLE) {
+ status_t err = mBufferMapper.registerBuffer(this);
+ if (err != NO_ERROR) {
+ // clean up cloned handle
+ if (clone) {
+ native_handle_close(clone);
+ native_handle_delete(clone);
+ }
+
+ initWithHandle(nullptr, WRAP_HANDLE, 0, 0, 0, 0, 0, 0, 0);
+
+ return err;
+ }
+ }
+
+ return NO_ERROR;
+}
+
status_t GraphicBuffer::lock(uint32_t inUsage, void** vaddr)
{
const Rect lockBounds(width, height);
diff --git a/libs/vr/libbufferhub/ion_buffer.cpp b/libs/vr/libbufferhub/ion_buffer.cpp
index 3fb3f3c..e5a56c1 100644
--- a/libs/vr/libbufferhub/ion_buffer.cpp
+++ b/libs/vr/libbufferhub/ion_buffer.cpp
@@ -1,5 +1,4 @@
#include <private/dvr/ion_buffer.h>
-#include <ui/GraphicBufferMapper.h>
#include <log/log.h>
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
@@ -70,10 +69,9 @@
ALOGD_IF(TRACE, "IonBuffer::Alloc: width=%d height=%d format=%d usage=%d",
width, height, format, usage);
- GraphicBufferMapper& mapper = GraphicBufferMapper::get();
buffer_ = new GraphicBuffer(width, height, format, usage);
- if (mapper.registerBuffer(buffer_.get()) != OK) {
- ALOGE("IonBuffer::Aloc: Failed to register buffer");
+ if (buffer_->initCheck() != OK) {
+ ALOGE("IonBuffer::Aloc: Failed to allocate buffer");
}
return 0;
}
@@ -96,11 +94,10 @@
"usage=%d",
handle, width, height, stride, format, usage);
FreeHandle();
- GraphicBufferMapper& mapper = GraphicBufferMapper::get();
- buffer_ = new GraphicBuffer(width, height, format, 1, usage,
- stride, (native_handle_t*)handle, true);
- if (mapper.registerBuffer(buffer_.get()) != OK) {
- ALOGE("IonBuffer::Import: Failed to register cloned buffer");
+ buffer_ = new GraphicBuffer(handle, GraphicBuffer::TAKE_UNREGISTERED_HANDLE,
+ width, height, format, 1, usage, stride);
+ if (buffer_->initCheck() != OK) {
+ ALOGE("IonBuffer::Import: Failed to import buffer");
return -EINVAL;
}
return 0;
diff --git a/libs/vr/libdvr/Android.mk b/libs/vr/libdvr/Android.mk
index 5449cb5..3c6934b 100644
--- a/libs/vr/libdvr/Android.mk
+++ b/libs/vr/libdvr/Android.mk
@@ -33,6 +33,7 @@
dvr_api.cpp \
dvr_buffer.cpp \
dvr_buffer_queue.cpp \
+ dvr_hardware_composer_client.cpp \
dvr_surface.cpp \
vsync_client_api.cpp \
@@ -42,12 +43,15 @@
libdisplay \
libvrsensor \
libvirtualtouchpadclient \
+ libvr_hwc-impl \
+ libvr_hwc-binder \
LOCAL_SHARED_LIBRARIES := \
android.hardware.graphics.bufferqueue@1.0 \
android.hidl.token@1.0-utils \
libandroid_runtime \
libbase \
+ libnativewindow \
include $(BUILD_STATIC_LIBRARY)
diff --git a/libs/vr/libdvr/dvr_api.cpp b/libs/vr/libdvr/dvr_api.cpp
index f464411..f786c29 100644
--- a/libs/vr/libdvr/dvr_api.cpp
+++ b/libs/vr/libdvr/dvr_api.cpp
@@ -11,6 +11,7 @@
// Headers not yet moved into libdvr.
// TODO(jwcai) Move these once their callers are moved into Google3.
+#include <dvr/dvr_hardware_composer_client.h>
#include <dvr/pose_client.h>
#include <dvr/virtual_touchpad_client.h>
@@ -100,6 +101,26 @@
dvr_api->virtual_touchpad_touch = dvrVirtualTouchpadTouch;
dvr_api->virtual_touchpad_button_state = dvrVirtualTouchpadButtonState;
+ // dvr_hardware_composer_client.h
+ dvr_api->hwc_client_create = dvrHwcClientCreate;
+ dvr_api->hwc_client_destroy = dvrHwcClientDestroy;
+ dvr_api->hwc_frame_destroy = dvrHwcFrameDestroy;
+ dvr_api->hwc_frame_get_display_id = dvrHwcFrameGetDisplayId;
+ dvr_api->hwc_frame_get_display_width = dvrHwcFrameGetDisplayWidth;
+ dvr_api->hwc_frame_get_display_height = dvrHwcFrameGetDisplayHeight;
+ dvr_api->hwc_frame_get_layer_count = dvrHwcFrameGetLayerCount;
+ dvr_api->hwc_frame_get_layer_id = dvrHwcFrameGetLayerId;
+ dvr_api->hwc_frame_get_layer_buffer = dvrHwcFrameGetLayerBuffer;
+ dvr_api->hwc_frame_get_layer_fence = dvrHwcFrameGetLayerFence;
+ dvr_api->hwc_frame_get_layer_display_frame =
+ dvrHwcFrameGetLayerDisplayFrame;
+ dvr_api->hwc_frame_get_layer_crop = dvrHwcFrameGetLayerCrop;
+ dvr_api->hwc_frame_get_layer_blend_mode = dvrHwcFrameGetLayerBlendMode;
+ dvr_api->hwc_frame_get_layer_alpha = dvrHwcFrameGetLayerAlpha;
+ dvr_api->hwc_frame_get_layer_type = dvrHwcFrameGetLayerType;
+ dvr_api->hwc_frame_get_layer_application_id =
+ dvrHwcFrameGetLayerApplicationId;
+
return 0;
}
return -EINVAL;
diff --git a/services/vr/hardware_composer/dvr_hardware_composer_client.cpp b/libs/vr/libdvr/dvr_hardware_composer_client.cpp
similarity index 79%
rename from services/vr/hardware_composer/dvr_hardware_composer_client.cpp
rename to libs/vr/libdvr/dvr_hardware_composer_client.cpp
index 39fa9fc..e5665e1 100644
--- a/services/vr/hardware_composer/dvr_hardware_composer_client.cpp
+++ b/libs/vr/libdvr/dvr_hardware_composer_client.cpp
@@ -1,7 +1,8 @@
-#include "private/android/dvr_hardware_composer_client.h"
+#include "include/dvr/dvr_hardware_composer_client.h"
#include <android/dvr/IVrComposer.h>
#include <android/dvr/BnVrComposerCallback.h>
+#include <android/hardware_buffer.h>
#include <binder/IServiceManager.h>
#include <private/android/AHardwareBufferHelpers.h>
@@ -15,7 +16,8 @@
class HwcCallback : public android::dvr::BnVrComposerCallback {
public:
- explicit HwcCallback(DvrHwcOnFrameCallback callback);
+ explicit HwcCallback(DvrHwcOnFrameCallback callback,
+ void* client_state);
~HwcCallback() override;
std::unique_ptr<DvrHwcFrame> DequeueFrame();
@@ -27,13 +29,14 @@
android::dvr::ParcelableUniqueFd* fence) override;
DvrHwcOnFrameCallback callback_;
+ void* client_state_;
HwcCallback(const HwcCallback&) = delete;
void operator=(const HwcCallback&) = delete;
};
-HwcCallback::HwcCallback(DvrHwcOnFrameCallback callback)
- : callback_(callback) {}
+HwcCallback::HwcCallback(DvrHwcOnFrameCallback callback, void* client_state)
+ : callback_(callback), client_state_(client_state) {}
HwcCallback::~HwcCallback() {}
@@ -43,7 +46,8 @@
std::unique_ptr<DvrHwcFrame> dvr_frame(new DvrHwcFrame());
dvr_frame->frame = frame.frame();
- fence->set_fence(android::base::unique_fd(callback_(dvr_frame.release())));
+ fence->set_fence(android::base::unique_fd(callback_(client_state_,
+ dvr_frame.release())));
return android::binder::Status::ok();
}
@@ -54,7 +58,7 @@
android::sp<HwcCallback> callback;
};
-DvrHwcClient* dvrHwcCreateClient(DvrHwcOnFrameCallback callback) {
+DvrHwcClient* dvrHwcClientCreate(DvrHwcOnFrameCallback callback, void* data) {
std::unique_ptr<DvrHwcClient> client(new DvrHwcClient());
android::sp<android::IServiceManager> sm(android::defaultServiceManager());
@@ -63,7 +67,7 @@
if (!client->composer.get())
return nullptr;
- client->callback = new HwcCallback(callback);
+ client->callback = new HwcCallback(callback, data);
android::binder::Status status = client->composer->registerObserver(
client->callback);
if (!status.isOk())
@@ -72,6 +76,10 @@
return client.release();
}
+void dvrHwcClientDestroy(DvrHwcClient* client) {
+ delete client;
+}
+
void dvrHwcFrameDestroy(DvrHwcFrame* frame) {
delete frame;
}
@@ -80,6 +88,18 @@
return frame->frame.display_id;
}
+int32_t dvrHwcFrameGetDisplayWidth(DvrHwcFrame* frame) {
+ return frame->frame.display_width;
+}
+
+int32_t dvrHwcFrameGetDisplayHeight(DvrHwcFrame* frame) {
+ return frame->frame.display_height;
+}
+
+bool dvrHwcFrameGetDisplayRemoved(DvrHwcFrame* frame) {
+ return frame->frame.removed;
+}
+
size_t dvrHwcFrameGetLayerCount(DvrHwcFrame* frame) {
return frame->frame.layers.size();
}
diff --git a/libs/vr/libdvr/include/dvr/dvr_api.h b/libs/vr/libdvr/include/dvr/dvr_api.h
index d840b6c..053382f 100644
--- a/libs/vr/libdvr/include/dvr/dvr_api.h
+++ b/libs/vr/libdvr/include/dvr/dvr_api.h
@@ -5,6 +5,7 @@
#include <stddef.h>
#include <stdint.h>
+#include <dvr/dvr_hardware_composer_defs.h>
#include <jni.h>
#ifdef __cplusplus
@@ -144,6 +145,37 @@
typedef int (*DvrVirtualTouchpadButtonStatePtr)(DvrVirtualTouchpad* client,
int touchpad, int buttons);
+// dvr_hardware_composer_client.h
+typedef struct DvrHwcClient DvrHwcClient;
+typedef struct DvrHwcFrame DvrHwcFrame;
+typedef int(*DvrHwcOnFrameCallback)(void* client_state, DvrHwcFrame* frame);
+typedef DvrHwcClient* (*DvrHwcClientCreatePtr)(DvrHwcOnFrameCallback callback,
+ void* client_state);
+typedef void (*DvrHwcClientDestroyPtr)(DvrHwcClient* client);
+typedef void (*DvrHwcFrameDestroyPtr)(DvrHwcFrame* frame);
+typedef Display (*DvrHwcFrameGetDisplayIdPtr)(DvrHwcFrame* frame);
+typedef int32_t (*DvrHwcFrameGetDisplayWidthPtr)(DvrHwcFrame* frame);
+typedef int32_t (*DvrHwcFrameGetDisplayHeightPtr)(DvrHwcFrame* frame);
+typedef bool (*DvrHwcFrameGetDisplayRemovedPtr)(DvrHwcFrame* frame);
+typedef size_t (*DvrHwcFrameGetLayerCountPtr)(DvrHwcFrame* frame);
+typedef Layer (*DvrHwcFrameGetLayerIdPtr)(DvrHwcFrame* frame, size_t layer_index);
+typedef AHardwareBuffer* (*DvrHwcFrameGetLayerBufferPtr)(DvrHwcFrame* frame,
+ size_t layer_index);
+typedef int (*DvrHwcFrameGetLayerFencePtr)(DvrHwcFrame* frame,
+ size_t layer_index);
+typedef Recti (*DvrHwcFrameGetLayerDisplayFramePtr)(DvrHwcFrame* frame,
+ size_t layer_index);
+typedef Rectf (*DvrHwcFrameGetLayerCropPtr)(DvrHwcFrame* frame,
+ size_t layer_index);
+typedef BlendMode (*DvrHwcFrameGetLayerBlendModePtr)(DvrHwcFrame* frame,
+ size_t layer_index);
+typedef float (*DvrHwcFrameGetLayerAlphaPtr)(DvrHwcFrame* frame,
+ size_t layer_index);
+typedef uint32_t (*DvrHwcFrameGetLayerTypePtr)(DvrHwcFrame* frame,
+ size_t layer_index);
+typedef uint32_t (*DvrHwcFrameGetLayerApplicationIdPtr)(DvrHwcFrame* frame,
+ size_t layer_index);
+
struct DvrApi_v1 {
// Display manager client
DvrDisplayManagerClientCreatePtr display_manager_client_create;
@@ -220,6 +252,25 @@
DvrVirtualTouchpadDetachPtr virtual_touchpad_detach;
DvrVirtualTouchpadTouchPtr virtual_touchpad_touch;
DvrVirtualTouchpadButtonStatePtr virtual_touchpad_button_state;
+
+ // VR HWComposer client
+ DvrHwcClientCreatePtr hwc_client_create;
+ DvrHwcClientDestroyPtr hwc_client_destroy;
+ DvrHwcFrameDestroyPtr hwc_frame_destroy;
+ DvrHwcFrameGetDisplayIdPtr hwc_frame_get_display_id;
+ DvrHwcFrameGetDisplayWidthPtr hwc_frame_get_display_width;
+ DvrHwcFrameGetDisplayHeightPtr hwc_frame_get_display_height;
+ DvrHwcFrameGetDisplayRemovedPtr hwc_frame_get_display_removed;
+ DvrHwcFrameGetLayerCountPtr hwc_frame_get_layer_count;
+ DvrHwcFrameGetLayerIdPtr hwc_frame_get_layer_id;
+ DvrHwcFrameGetLayerBufferPtr hwc_frame_get_layer_buffer;
+ DvrHwcFrameGetLayerFencePtr hwc_frame_get_layer_fence;
+ DvrHwcFrameGetLayerDisplayFramePtr hwc_frame_get_layer_display_frame;
+ DvrHwcFrameGetLayerCropPtr hwc_frame_get_layer_crop;
+ DvrHwcFrameGetLayerBlendModePtr hwc_frame_get_layer_blend_mode;
+ DvrHwcFrameGetLayerAlphaPtr hwc_frame_get_layer_alpha;
+ DvrHwcFrameGetLayerTypePtr hwc_frame_get_layer_type;
+ DvrHwcFrameGetLayerApplicationIdPtr hwc_frame_get_layer_application_id;
};
int dvrGetApi(void* api, size_t struct_size, int version);
diff --git a/services/vr/hardware_composer/private/android/dvr_hardware_composer_client.h b/libs/vr/libdvr/include/dvr/dvr_hardware_composer_client.h
similarity index 61%
rename from services/vr/hardware_composer/private/android/dvr_hardware_composer_client.h
rename to libs/vr/libdvr/include/dvr/dvr_hardware_composer_client.h
index 063c16d..692864d 100644
--- a/services/vr/hardware_composer/private/android/dvr_hardware_composer_client.h
+++ b/libs/vr/libdvr/include/dvr/dvr_hardware_composer_client.h
@@ -1,29 +1,45 @@
-#ifndef VR_HARDWARE_COMPOSER_PRIVATE_ANDROID_DVR_HARDWARE_COMPOSER_CLIENT_H
-#define VR_HARDWARE_COMPOSER_PRIVATE_ANDROID_DVR_HARDWARE_COMPOSER_CLIENT_H
+#ifndef ANDROID_DVR_HARDWARE_COMPOSER_CLIENT_H
+#define ANDROID_DVR_HARDWARE_COMPOSER_CLIENT_H
-#include <android/dvr_hardware_composer_defs.h>
-#include <android/hardware_buffer.h>
+#include <dvr/dvr_hardware_composer_defs.h>
+#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
+typedef struct AHardwareBuffer AHardwareBuffer;
typedef struct DvrHwcClient DvrHwcClient;
typedef struct DvrHwcFrame DvrHwcFrame;
// Called when a new frame has arrived.
//
+// @param client_state Pointer to client state passed in |dvrHwcCreateClient()|.
// @param frame New frame. Owned by the client.
// @return fence FD for the release of the last frame.
-typedef int(*DvrHwcOnFrameCallback)(DvrHwcFrame* frame);
+typedef int(*DvrHwcOnFrameCallback)(void* client_state, DvrHwcFrame* frame);
-DvrHwcClient* dvrHwcCreateClient(DvrHwcOnFrameCallback callback);
+// @param callback Called when a new frame is available.
+// @param client_state Pointer to client state passed back in the callback.
+DvrHwcClient* dvrHwcClientCreate(DvrHwcOnFrameCallback callback,
+ void* client_state);
+
+void dvrHwcClientDestroy(DvrHwcClient* client);
// Called to free the frame information.
void dvrHwcFrameDestroy(DvrHwcFrame* frame);
Display dvrHwcFrameGetDisplayId(DvrHwcFrame* frame);
+int32_t dvrHwcFrameGetDisplayWidth(DvrHwcFrame* frame);
+
+int32_t dvrHwcFrameGetDisplayHeight(DvrHwcFrame* frame);
+
+// @return True if the display has been removed. In this case the current frame
+// does not contain any valid layers to display. It is a signal to clean up any
+// display related state.
+bool dvrHwcFrameGetDisplayRemoved(DvrHwcFrame* frame);
+
// @return Number of layers in the frame.
size_t dvrHwcFrameGetLayerCount(DvrHwcFrame* frame);
@@ -59,4 +75,4 @@
} // extern "C"
#endif
-#endif // VR_HARDWARE_COMPOSER_PRIVATE_ANDROID_DVR_HARDWARE_COMPOSER_CLIENT_H
+#endif // ANDROID_DVR_HARDWARE_COMPOSER_CLIENT_H
diff --git a/services/vr/hardware_composer/private/android/dvr_hardware_composer_defs.h b/libs/vr/libdvr/include/dvr/dvr_hardware_composer_defs.h
similarity index 78%
rename from services/vr/hardware_composer/private/android/dvr_hardware_composer_defs.h
rename to libs/vr/libdvr/include/dvr/dvr_hardware_composer_defs.h
index 3186f82..546ed7b 100644
--- a/services/vr/hardware_composer/private/android/dvr_hardware_composer_defs.h
+++ b/libs/vr/libdvr/include/dvr/dvr_hardware_composer_defs.h
@@ -1,5 +1,5 @@
-#ifndef VR_HARDWARE_COMPOSER_PRIVATE_ANDROID_VR_HARDWARE_COMPOSER_DEFS_H
-#define VR_HARDWARE_COMPOSER_PRIVATE_ANDROID_VR_HARDWARE_COMPOSER_DEFS_H
+#ifndef ANDROID_VR_HARDWARE_COMPOSER_DEFS_H
+#define ANDROID_VR_HARDWARE_COMPOSER_DEFS_H
#include <inttypes.h>
@@ -47,4 +47,4 @@
} // extern "C"
#endif
-#endif // VR_HARDWARE_COMPOSER_PRIVATE_ANDROID_DVR_HARDWARE_COMPOSER_DEFS_H
+#endif // ANDROID_DVR_HARDWARE_COMPOSER_DEFS_H
diff --git a/libs/vr/libpdx/client.cpp b/libs/vr/libpdx/client.cpp
index c318628..bfa2d87 100644
--- a/libs/vr/libpdx/client.cpp
+++ b/libs/vr/libpdx/client.cpp
@@ -4,7 +4,6 @@
#include <log/log.h>
#include <pdx/trace.h>
-#include "errno_guard.h"
namespace android {
namespace pdx {
@@ -84,7 +83,6 @@
Status<void> Client::SendImpulse(int opcode) {
PDX_TRACE_NAME("Client::SendImpulse");
- ErrnoGuard errno_guard;
auto status = CheckReconnect();
if (!status)
@@ -98,7 +96,6 @@
Status<void> Client::SendImpulse(int opcode, const void* buffer,
size_t length) {
PDX_TRACE_NAME("Client::SendImpulse");
- ErrnoGuard errno_guard;
auto status = CheckReconnect();
if (!status)
@@ -110,7 +107,6 @@
}
void Client::Close(int error) {
- ErrnoGuard errno_guard;
channel_.reset();
// Normalize error codes to negative integer space.
error_ = error <= 0 ? error : -error;
@@ -228,37 +224,38 @@
CheckDisconnect(*ret);
}
-FileReference Transaction::PushFileHandle(const LocalHandle& handle) {
- return client_.CheckReconnect() && EnsureStateAllocated()
- ? client_.GetChannel()->PushFileHandle(state_, handle)
- : -1;
+Status<FileReference> Transaction::PushFileHandle(const LocalHandle& handle) {
+ if (client_.CheckReconnect() && EnsureStateAllocated())
+ return client_.GetChannel()->PushFileHandle(state_, handle);
+ return ErrorStatus{ESHUTDOWN};
}
-FileReference Transaction::PushFileHandle(const BorrowedHandle& handle) {
- return client_.CheckReconnect() && EnsureStateAllocated()
- ? client_.GetChannel()->PushFileHandle(state_, handle)
- : -1;
+Status<FileReference> Transaction::PushFileHandle(
+ const BorrowedHandle& handle) {
+ if (client_.CheckReconnect() && EnsureStateAllocated())
+ return client_.GetChannel()->PushFileHandle(state_, handle);
+ return ErrorStatus{ESHUTDOWN};
}
-FileReference Transaction::PushFileHandle(const RemoteHandle& handle) {
+Status<FileReference> Transaction::PushFileHandle(const RemoteHandle& handle) {
return handle.Get();
}
-ChannelReference Transaction::PushChannelHandle(
+Status<ChannelReference> Transaction::PushChannelHandle(
const LocalChannelHandle& handle) {
- return client_.CheckReconnect() && EnsureStateAllocated()
- ? client_.GetChannel()->PushChannelHandle(state_, handle)
- : -1;
+ if (client_.CheckReconnect() && EnsureStateAllocated())
+ return client_.GetChannel()->PushChannelHandle(state_, handle);
+ return ErrorStatus{ESHUTDOWN};
}
-ChannelReference Transaction::PushChannelHandle(
+Status<ChannelReference> Transaction::PushChannelHandle(
const BorrowedChannelHandle& handle) {
- return client_.CheckReconnect() && EnsureStateAllocated()
- ? client_.GetChannel()->PushChannelHandle(state_, handle)
- : -1;
+ if (client_.CheckReconnect() && EnsureStateAllocated())
+ return client_.GetChannel()->PushChannelHandle(state_, handle);
+ return ErrorStatus{ESHUTDOWN};
}
-ChannelReference Transaction::PushChannelHandle(
+Status<ChannelReference> Transaction::PushChannelHandle(
const RemoteChannelHandle& handle) {
return handle.value();
}
diff --git a/libs/vr/libpdx/client_tests.cpp b/libs/vr/libpdx/client_tests.cpp
index f1fb6d1..99ccc69 100644
--- a/libs/vr/libpdx/client_tests.cpp
+++ b/libs/vr/libpdx/client_tests.cpp
@@ -518,28 +518,29 @@
EXPECT_CALL(*mock_channel(),
PushFileHandle(kTransactionState, A<const LocalHandle&>()))
.WillOnce(Return(1));
- EXPECT_EQ(1, transaction_.PushFileHandle(LocalHandle{-1}));
+ EXPECT_EQ(1, transaction_.PushFileHandle(LocalHandle{-1}).get());
EXPECT_CALL(*mock_channel(),
PushFileHandle(kTransactionState, A<const BorrowedHandle&>()))
.WillOnce(Return(2));
- EXPECT_EQ(2, transaction_.PushFileHandle(BorrowedHandle{-1}));
+ EXPECT_EQ(2, transaction_.PushFileHandle(BorrowedHandle{-1}).get());
- EXPECT_EQ(3, transaction_.PushFileHandle(RemoteHandle{3}));
+ EXPECT_EQ(3, transaction_.PushFileHandle(RemoteHandle{3}).get());
EXPECT_CALL(
*mock_channel(),
PushChannelHandle(kTransactionState, A<const LocalChannelHandle&>()))
.WillOnce(Return(11));
- EXPECT_EQ(11, transaction_.PushChannelHandle(LocalChannelHandle{nullptr, 1}));
+ EXPECT_EQ(
+ 11, transaction_.PushChannelHandle(LocalChannelHandle{nullptr, 1}).get());
EXPECT_CALL(
*mock_channel(),
PushChannelHandle(kTransactionState, A<const BorrowedChannelHandle&>()))
.WillOnce(Return(12));
- EXPECT_EQ(12, transaction_.PushChannelHandle(BorrowedChannelHandle{2}));
+ EXPECT_EQ(12, transaction_.PushChannelHandle(BorrowedChannelHandle{2}).get());
- EXPECT_EQ(13, transaction_.PushChannelHandle(RemoteChannelHandle{13}));
+ EXPECT_EQ(13, transaction_.PushChannelHandle(RemoteChannelHandle{13}).get());
}
TEST_F(ClientTransactionTest, GetHandle) {
diff --git a/libs/vr/libpdx/errno_guard.h b/libs/vr/libpdx/errno_guard.h
deleted file mode 100644
index fc7dfdf..0000000
--- a/libs/vr/libpdx/errno_guard.h
+++ /dev/null
@@ -1,34 +0,0 @@
-#ifndef ANDROID_PDX_ERRNO_GUARD_H_
-#define ANDROID_PDX_ERRNO_GUARD_H_
-
-#include <errno.h>
-
-namespace android {
-namespace pdx {
-
-// Automatically saves and restores the system errno for API implementations to
-// prevent internal use errno from affecting API callers.
-class ErrnoGuard {
- public:
- ErrnoGuard() : saved_errno_(errno) {}
- ~ErrnoGuard() { errno = saved_errno_; }
-
- int saved_errno() const { return saved_errno_; }
-
- private:
- int saved_errno_;
-
- ErrnoGuard(const ErrnoGuard&) = delete;
- void operator=(const ErrnoGuard&) = delete;
-};
-
-// Checks |return_code| and returns either it or the negated system errno based
-// on the return code value.
-inline int ReturnCodeOrError(int return_code) {
- return return_code < 0 ? -errno : return_code;
-}
-
-} // namespace pdx
-} // namespace android
-
-#endif // ANDROID_PDX_ERRNO_GUARD_H_
diff --git a/libs/vr/libpdx/private/pdx/client.h b/libs/vr/libpdx/private/pdx/client.h
index a590087..656de7e 100644
--- a/libs/vr/libpdx/private/pdx/client.h
+++ b/libs/vr/libpdx/private/pdx/client.h
@@ -253,13 +253,14 @@
}
// OutputResourceMapper
- FileReference PushFileHandle(const LocalHandle& handle) override;
- FileReference PushFileHandle(const BorrowedHandle& handle) override;
- FileReference PushFileHandle(const RemoteHandle& handle) override;
- ChannelReference PushChannelHandle(const LocalChannelHandle& handle) override;
- ChannelReference PushChannelHandle(
+ Status<FileReference> PushFileHandle(const LocalHandle& handle) override;
+ Status<FileReference> PushFileHandle(const BorrowedHandle& handle) override;
+ Status<FileReference> PushFileHandle(const RemoteHandle& handle) override;
+ Status<ChannelReference> PushChannelHandle(
+ const LocalChannelHandle& handle) override;
+ Status<ChannelReference> PushChannelHandle(
const BorrowedChannelHandle& handle) override;
- ChannelReference PushChannelHandle(
+ Status<ChannelReference> PushChannelHandle(
const RemoteChannelHandle& handle) override;
// InputResourceMapper
diff --git a/libs/vr/libpdx/private/pdx/message_writer.h b/libs/vr/libpdx/private/pdx/message_writer.h
index 0cb6e40..4a101d6 100644
--- a/libs/vr/libpdx/private/pdx/message_writer.h
+++ b/libs/vr/libpdx/private/pdx/message_writer.h
@@ -3,20 +3,22 @@
#include <pdx/channel_handle.h>
#include <pdx/file_handle.h>
+#include <pdx/status.h>
namespace android {
namespace pdx {
class OutputResourceMapper {
public:
- virtual FileReference PushFileHandle(const LocalHandle& handle) = 0;
- virtual FileReference PushFileHandle(const BorrowedHandle& handle) = 0;
- virtual FileReference PushFileHandle(const RemoteHandle& handle) = 0;
- virtual ChannelReference PushChannelHandle(
+ virtual Status<FileReference> PushFileHandle(const LocalHandle& handle) = 0;
+ virtual Status<FileReference> PushFileHandle(
+ const BorrowedHandle& handle) = 0;
+ virtual Status<FileReference> PushFileHandle(const RemoteHandle& handle) = 0;
+ virtual Status<ChannelReference> PushChannelHandle(
const LocalChannelHandle& handle) = 0;
- virtual ChannelReference PushChannelHandle(
+ virtual Status<ChannelReference> PushChannelHandle(
const BorrowedChannelHandle& handle) = 0;
- virtual ChannelReference PushChannelHandle(
+ virtual Status<ChannelReference> PushChannelHandle(
const RemoteChannelHandle& handle) = 0;
protected:
diff --git a/libs/vr/libpdx/private/pdx/mock_message_writer.h b/libs/vr/libpdx/private/pdx/mock_message_writer.h
index 3c513d7..e06e5bb 100644
--- a/libs/vr/libpdx/private/pdx/mock_message_writer.h
+++ b/libs/vr/libpdx/private/pdx/mock_message_writer.h
@@ -9,15 +9,18 @@
class MockOutputResourceMapper : public OutputResourceMapper {
public:
- MOCK_METHOD1(PushFileHandle, FileReference(const LocalHandle& handle));
- MOCK_METHOD1(PushFileHandle, FileReference(const BorrowedHandle& handle));
- MOCK_METHOD1(PushFileHandle, FileReference(const RemoteHandle& handle));
+ MOCK_METHOD1(PushFileHandle,
+ Status<FileReference>(const LocalHandle& handle));
+ MOCK_METHOD1(PushFileHandle,
+ Status<FileReference>(const BorrowedHandle& handle));
+ MOCK_METHOD1(PushFileHandle,
+ Status<FileReference>(const RemoteHandle& handle));
MOCK_METHOD1(PushChannelHandle,
- ChannelReference(const LocalChannelHandle& handle));
+ Status<ChannelReference>(const LocalChannelHandle& handle));
MOCK_METHOD1(PushChannelHandle,
- ChannelReference(const BorrowedChannelHandle& handle));
+ Status<ChannelReference>(const BorrowedChannelHandle& handle));
MOCK_METHOD1(PushChannelHandle,
- ChannelReference(const RemoteChannelHandle& handle));
+ Status<ChannelReference>(const RemoteChannelHandle& handle));
};
class MockMessageWriter : public MessageWriter {
diff --git a/libs/vr/libpdx/private/pdx/mock_service_endpoint.h b/libs/vr/libpdx/private/pdx/mock_service_endpoint.h
index ead74d5..e741d4a 100644
--- a/libs/vr/libpdx/private/pdx/mock_service_endpoint.h
+++ b/libs/vr/libpdx/private/pdx/mock_service_endpoint.h
@@ -10,46 +10,54 @@
class MockEndpoint : public Endpoint {
public:
MOCK_CONST_METHOD0(GetIpcTag, uint32_t());
- MOCK_METHOD1(SetService, int(Service* service));
- MOCK_METHOD2(SetChannel, int(int channel_id, Channel* channel));
- MOCK_METHOD1(CloseChannel, int(int channel_id));
+ MOCK_METHOD1(SetService, Status<void>(Service* service));
+ MOCK_METHOD2(SetChannel, Status<void>(int channel_id, Channel* channel));
+ MOCK_METHOD1(CloseChannel, Status<void>(int channel_id));
MOCK_METHOD3(ModifyChannelEvents,
- int(int channel_id, int clear_mask, int set_mask));
+ Status<void>(int channel_id, int clear_mask, int set_mask));
MOCK_METHOD4(PushChannel,
Status<RemoteChannelHandle>(Message* message, int flags,
Channel* channel, int* channel_id));
MOCK_METHOD3(CheckChannel,
Status<int>(const Message* message, ChannelReference ref,
Channel** channel));
- MOCK_METHOD1(DefaultHandleMessage, int(const MessageInfo& info));
- MOCK_METHOD1(MessageReceive, int(Message* message));
- MOCK_METHOD2(MessageReply, int(Message* message, int return_code));
- MOCK_METHOD2(MessageReplyFd, int(Message* message, unsigned int push_fd));
+ MOCK_METHOD1(MessageReceive, Status<void>(Message* message));
+ MOCK_METHOD2(MessageReply, Status<void>(Message* message, int return_code));
+ MOCK_METHOD2(MessageReplyFd,
+ Status<void>(Message* message, unsigned int push_fd));
MOCK_METHOD2(MessageReplyChannelHandle,
- int(Message* message, const LocalChannelHandle& handle));
+ Status<void>(Message* message,
+ const LocalChannelHandle& handle));
MOCK_METHOD2(MessageReplyChannelHandle,
- int(Message* message, const BorrowedChannelHandle& handle));
+ Status<void>(Message* message,
+ const BorrowedChannelHandle& handle));
MOCK_METHOD2(MessageReplyChannelHandle,
- int(Message* message, const RemoteChannelHandle& handle));
- MOCK_METHOD3(ReadMessageData, ssize_t(Message* message, const iovec* vector,
- size_t vector_length));
- MOCK_METHOD3(WriteMessageData, ssize_t(Message* message, const iovec* vector,
- size_t vector_length));
+ Status<void>(Message* message,
+ const RemoteChannelHandle& handle));
+ MOCK_METHOD3(ReadMessageData,
+ Status<size_t>(Message* message, const iovec* vector,
+ size_t vector_length));
+ MOCK_METHOD3(WriteMessageData,
+ Status<size_t>(Message* message, const iovec* vector,
+ size_t vector_length));
MOCK_METHOD2(PushFileHandle,
- FileReference(Message* message, const LocalHandle& handle));
+ Status<FileReference>(Message* message,
+ const LocalHandle& handle));
MOCK_METHOD2(PushFileHandle,
- FileReference(Message* message, const BorrowedHandle& handle));
+ Status<FileReference>(Message* message,
+ const BorrowedHandle& handle));
MOCK_METHOD2(PushFileHandle,
- FileReference(Message* message, const RemoteHandle& handle));
+ Status<FileReference>(Message* message,
+ const RemoteHandle& handle));
MOCK_METHOD2(PushChannelHandle,
- ChannelReference(Message* message,
- const LocalChannelHandle& handle));
+ Status<ChannelReference>(Message* message,
+ const LocalChannelHandle& handle));
MOCK_METHOD2(PushChannelHandle,
- ChannelReference(Message* message,
- const BorrowedChannelHandle& handle));
+ Status<ChannelReference>(Message* message,
+ const BorrowedChannelHandle& handle));
MOCK_METHOD2(PushChannelHandle,
- ChannelReference(Message* message,
- const RemoteChannelHandle& handle));
+ Status<ChannelReference>(Message* message,
+ const RemoteChannelHandle& handle));
MOCK_CONST_METHOD2(GetFileHandle,
LocalHandle(Message* message, FileReference ref));
MOCK_CONST_METHOD2(GetChannelHandle,
@@ -57,7 +65,7 @@
ChannelReference ref));
MOCK_METHOD0(AllocateMessageState, void*());
MOCK_METHOD1(FreeMessageState, void(void* state));
- MOCK_METHOD0(Cancel, int());
+ MOCK_METHOD0(Cancel, Status<void>());
};
} // namespace pdx
diff --git a/libs/vr/libpdx/private/pdx/rpc/remote_method.h b/libs/vr/libpdx/private/pdx/rpc/remote_method.h
index 3eca9e5..505c63b 100644
--- a/libs/vr/libpdx/private/pdx/rpc/remote_method.h
+++ b/libs/vr/libpdx/private/pdx/rpc/remote_method.h
@@ -121,9 +121,9 @@
// either during dispatch of the remote method handler or at a later time if the
// message is moved for delayed response.
inline void RemoteMethodError(Message& message, int error_code) {
- const int ret = message.ReplyError(error_code);
- ALOGE_IF(ret < 0, "RemoteMethodError: Failed to reply to message: %s",
- strerror(-ret));
+ const auto status = message.ReplyError(error_code);
+ ALOGE_IF(!status, "RemoteMethodError: Failed to reply to message: %s",
+ status.GetErrorMessage().c_str());
}
// Returns a value from a remote method to the client. The usual method to
@@ -135,9 +135,9 @@
template <typename RemoteMethodType, typename Return>
EnableIfDirectReturn<typename RemoteMethodType::Return> RemoteMethodReturn(
Message& message, const Return& return_value) {
- const int ret = message.Reply(return_value);
- ALOGE_IF(ret < 0, "RemoteMethodReturn: Failed to reply to message: %s",
- strerror(-ret));
+ const auto status = message.Reply(return_value);
+ ALOGE_IF(!status, "RemoteMethodReturn: Failed to reply to message: %s",
+ status.GetErrorMessage().c_str());
}
// Overload for non-direct return types.
@@ -148,14 +148,10 @@
rpc::ServicePayload<ReplyBuffer> payload(message);
MakeArgumentEncoder<Signature>(&payload).EncodeReturn(return_value);
- int ret;
- auto size = message.Write(payload.Data(), payload.Size());
- if (size < static_cast<decltype(size)>(payload.Size()))
- ret = message.ReplyError(EIO);
- else
- ret = message.Reply(0);
- ALOGE_IF(ret < 0, "RemoteMethodReturn: Failed to reply to message: %s",
- strerror(-ret));
+ auto ret = message.WriteAll(payload.Data(), payload.Size());
+ auto status = message.Reply(ret);
+ ALOGE_IF(!status, "RemoteMethodReturn: Failed to reply to message: %s",
+ status.GetErrorMessage().c_str());
}
// Overload for Status<void> return types.
@@ -189,13 +185,13 @@
rpc::ServicePayload<ReceiveBuffer> payload(message);
payload.Resize(max_capacity);
- auto size = message.Read(payload.Data(), payload.Size());
- if (size < 0) {
- RemoteMethodError(message, -size);
+ Status<size_t> read_status = message.Read(payload.Data(), payload.Size());
+ if (!read_status) {
+ RemoteMethodError(message, read_status.error());
return;
}
- payload.Resize(size);
+ payload.Resize(read_status.get());
ErrorType error;
auto decoder = MakeArgumentDecoder<Signature>(&payload);
@@ -225,13 +221,13 @@
rpc::ServicePayload<ReceiveBuffer> payload(message);
payload.Resize(max_capacity);
- auto size = message.Read(payload.Data(), payload.Size());
- if (size < 0) {
- RemoteMethodError(message, -size);
+ Status<size_t> read_status = message.Read(payload.Data(), payload.Size());
+ if (!read_status) {
+ RemoteMethodError(message, read_status.error());
return;
}
- payload.Resize(size);
+ payload.Resize(read_status.get());
ErrorType error;
auto decoder = MakeArgumentDecoder<Signature>(&payload);
@@ -265,13 +261,13 @@
rpc::ServicePayload<ReceiveBuffer> payload(message);
payload.Resize(max_capacity);
- auto size = message.Read(payload.Data(), payload.Size());
- if (size < 0) {
- RemoteMethodError(message, -size);
+ Status<size_t> read_status = message.Read(payload.Data(), payload.Size());
+ if (!read_status) {
+ RemoteMethodError(message, read_status.error());
return;
}
- payload.Resize(size);
+ payload.Resize(read_status.get());
ErrorType error;
auto decoder = MakeArgumentDecoder<Signature>(&payload);
diff --git a/libs/vr/libpdx/private/pdx/rpc/serialization.h b/libs/vr/libpdx/private/pdx/rpc/serialization.h
index fccd028..9a012ed 100644
--- a/libs/vr/libpdx/private/pdx/rpc/serialization.h
+++ b/libs/vr/libpdx/private/pdx/rpc/serialization.h
@@ -905,8 +905,9 @@
inline void SerializeObject(const FileHandle<Mode>& fd, MessageWriter* writer,
void*& buffer) {
SerializeType(fd, buffer);
- const FileReference value =
+ const Status<FileReference> status =
writer->GetOutputResourceMapper()->PushFileHandle(fd);
+ FileReference value = status ? status.get() : -status.error();
SerializeRaw(value, buffer);
}
@@ -915,8 +916,9 @@
inline void SerializeObject(const ChannelHandle<Mode>& handle,
MessageWriter* writer, void*& buffer) {
SerializeType(handle, buffer);
- const ChannelReference value =
+ const Status<ChannelReference> status =
writer->GetOutputResourceMapper()->PushChannelHandle(handle);
+ ChannelReference value = status ? status.get() : -status.error();
SerializeRaw(value, buffer);
}
diff --git a/libs/vr/libpdx/private/pdx/service.h b/libs/vr/libpdx/private/pdx/service.h
index 175cedf..0d30614 100644
--- a/libs/vr/libpdx/private/pdx/service.h
+++ b/libs/vr/libpdx/private/pdx/service.h
@@ -98,29 +98,62 @@
/*
* Read/write payload, in either single buffer or iovec form.
*/
- ssize_t ReadVector(const iovec* vector, size_t vector_length);
- ssize_t Read(void* buffer, size_t length);
- ssize_t WriteVector(const iovec* vector, size_t vector_length);
- ssize_t Write(const void* buffer, size_t length);
+ Status<size_t> ReadVector(const iovec* vector, size_t vector_length);
+ Status<size_t> Read(void* buffer, size_t length);
+ Status<size_t> WriteVector(const iovec* vector, size_t vector_length);
+ Status<size_t> Write(const void* buffer, size_t length);
template <size_t N>
- inline ssize_t ReadVector(const iovec (&vector)[N]) {
+ inline Status<size_t> ReadVector(const iovec (&vector)[N]) {
return ReadVector(vector, N);
}
template <size_t N>
- inline ssize_t WriteVector(const iovec (&vector)[N]) {
+ inline Status<size_t> WriteVector(const iovec (&vector)[N]) {
return WriteVector(vector, N);
}
+ // Helper functions to read/write all requested bytes, and return EIO if not
+ // all were read/written.
+ Status<void> ReadVectorAll(const iovec* vector, size_t vector_length);
+ Status<void> WriteVectorAll(const iovec* vector, size_t vector_length);
+
+ inline Status<void> ReadAll(void* buffer, size_t length) {
+ Status<size_t> status = Read(buffer, length);
+ if (status && status.get() < length)
+ status.SetError(EIO);
+ Status<void> ret;
+ ret.PropagateError(status);
+ return ret;
+ }
+ inline Status<void> WriteAll(const void* buffer, size_t length) {
+ Status<size_t> status = Write(buffer, length);
+ if (status && status.get() < length)
+ status.SetError(EIO);
+ Status<void> ret;
+ ret.PropagateError(status);
+ return ret;
+ }
+
+ template <size_t N>
+ inline Status<void> ReadVectorAll(const iovec (&vector)[N]) {
+ return ReadVectorAll(vector, N);
+ }
+
+ template <size_t N>
+ inline Status<void> WriteVectorAll(const iovec (&vector)[N]) {
+ return WriteVectorAll(vector, N);
+ }
+
// OutputResourceMapper
- FileReference PushFileHandle(const LocalHandle& handle) override;
- FileReference PushFileHandle(const BorrowedHandle& handle) override;
- FileReference PushFileHandle(const RemoteHandle& handle) override;
- ChannelReference PushChannelHandle(const LocalChannelHandle& handle) override;
- ChannelReference PushChannelHandle(
+ Status<FileReference> PushFileHandle(const LocalHandle& handle) override;
+ Status<FileReference> PushFileHandle(const BorrowedHandle& handle) override;
+ Status<FileReference> PushFileHandle(const RemoteHandle& handle) override;
+ Status<ChannelReference> PushChannelHandle(
+ const LocalChannelHandle& handle) override;
+ Status<ChannelReference> PushChannelHandle(
const BorrowedChannelHandle& handle) override;
- ChannelReference PushChannelHandle(
+ Status<ChannelReference> PushChannelHandle(
const RemoteChannelHandle& handle) override;
// InputResourceMapper
@@ -131,25 +164,29 @@
/*
* Various ways to reply to a message.
*/
- int Reply(int return_code);
- int ReplyError(unsigned error);
- int ReplyFileDescriptor(unsigned int fd);
- int Reply(const LocalHandle& handle);
- int Reply(const BorrowedHandle& handle);
- int Reply(const RemoteHandle& handle);
- int Reply(const LocalChannelHandle& handle);
- int Reply(const BorrowedChannelHandle& handle);
- int Reply(const RemoteChannelHandle& handle);
+ Status<void> Reply(int return_code);
+ Status<void> ReplyError(unsigned int error);
+ Status<void> ReplyFileDescriptor(unsigned int fd);
+ Status<void> Reply(const LocalHandle& handle);
+ Status<void> Reply(const BorrowedHandle& handle);
+ Status<void> Reply(const RemoteHandle& handle);
+ Status<void> Reply(const LocalChannelHandle& handle);
+ Status<void> Reply(const BorrowedChannelHandle& handle);
+ Status<void> Reply(const RemoteChannelHandle& handle);
template <typename T>
- inline int Reply(const Status<T>& status) {
+ inline Status<void> Reply(const Status<T>& status) {
return status ? Reply(status.get()) : ReplyError(status.error());
}
+ inline Status<void> Reply(const Status<void>& status) {
+ return status ? Reply(0) : ReplyError(status.error());
+ }
+
/*
* Update the channel event bits with the given clear and set masks.
*/
- int ModifyChannelEvents(int clear_mask, int set_mask);
+ Status<void> ModifyChannelEvents(int clear_mask, int set_mask);
/*
* Create a new channel and push it as a file descriptor to the client. See
@@ -264,7 +301,7 @@
* these in multi-threaded services.
*/
std::shared_ptr<Channel> GetChannel() const;
- void SetChannel(const std::shared_ptr<Channel>& channnel);
+ Status<void> SetChannel(const std::shared_ptr<Channel>& channnel);
/*
* Get the Channel object for the channel associated with this message,
@@ -355,7 +392,8 @@
* the Channel object until the channel is closed or another call replaces
* the current value.
*/
- int SetChannel(int channel_id, const std::shared_ptr<Channel>& channel);
+ Status<void> SetChannel(int channel_id,
+ const std::shared_ptr<Channel>& channel);
/*
* Get the channel context for the given channel id. This method should be
@@ -404,7 +442,7 @@
*
* OnChannelClosed is not called in response to this method call.
*/
- int CloseChannel(int channel_id);
+ Status<void> CloseChannel(int channel_id);
/*
* Update the event bits for the given channel (given by id), using the
@@ -413,7 +451,8 @@
* This is useful for asynchronously signaling events that clients may be
* waiting for using select/poll/epoll.
*/
- int ModifyChannelEvents(int channel_id, int clear_mask, int set_mask);
+ Status<void> ModifyChannelEvents(int channel_id, int clear_mask,
+ int set_mask);
/*
* Create a new channel and push it as a file descriptor to the process
@@ -478,7 +517,7 @@
* The default implementation simply calls defaultHandleMessage().
* Subclasses should call the same for any unrecognized message opcodes.
*/
- virtual int HandleMessage(Message& message);
+ virtual Status<void> HandleMessage(Message& message);
/*
* Handle an asynchronous message. Subclasses override this to receive
@@ -496,9 +535,9 @@
* Provides default handling of CHANNEL_OPEN and CHANNEL_CLOSE, calling
* OnChannelOpen() and OnChannelClose(), respectively.
*
- * For all other message opcodes, this method replies with -ENOTSUP.
+ * For all other message opcodes, this method replies with ENOTSUP.
*/
- int DefaultHandleMessage(Message& message);
+ Status<void> DefaultHandleMessage(Message& message);
/*
* Called when system properties have changed. Subclasses should implement
@@ -515,7 +554,7 @@
* Cancels the endpoint, unblocking any receiver threads waiting in
* ReceiveAndDispatch().
*/
- int Cancel();
+ Status<void> Cancel();
/*
* Iterator type for Channel map iterators.
@@ -564,14 +603,14 @@
* If the endpoint is in blocking mode this call blocks until a message is
* received, a signal is delivered to this thread, or the service is canceled.
* If the endpoint is in non-blocking mode and a message is not pending this
- * call returns immediately with -ETIMEDOUT.
+ * call returns immediately with ETIMEDOUT.
*/
- int ReceiveAndDispatch();
+ Status<void> ReceiveAndDispatch();
private:
friend class Message;
- bool HandleSystemMessage(Message& message);
+ Status<void> HandleSystemMessage(Message& message);
Service(const Service&);
void operator=(const Service&) = delete;
@@ -639,28 +678,28 @@
#define REPLY_ERROR(message, error, error_label) \
do { \
- int __ret = message.ReplyError(error); \
- CHECK_ERROR(__ret < 0, error_label, \
+ auto __status = message.ReplyError(error); \
+ CHECK_ERROR(!__status, error_label, \
PDX_ERROR_PREFIX " Failed to reply to message because: %s\n", \
- strerror(-__ret)); \
+ __status.GetErrorMessage().c_str()); \
goto error_label; \
} while (0)
#define REPLY_ERROR_RETURN(message, error, ...) \
do { \
- int __ret = message.ReplyError(error); \
- ALOGE_IF(__ret < 0, \
+ auto __status = message.ReplyError(error); \
+ ALOGE_IF(!__status, \
PDX_ERROR_PREFIX " Failed to reply to message because: %s", \
- strerror(-__ret)); \
+ __status.GetErrorMessage().c_str()); \
return __VA_ARGS__; \
} while (0)
#define REPLY_MESSAGE(message, message_return_code, error_label) \
do { \
- int __ret = message.Reply(message_return_code); \
- CHECK_ERROR(__ret < 0, error_label, \
+ auto __status = message.Reply(message_return_code); \
+ CHECK_ERROR(!__status, error_label, \
PDX_ERROR_PREFIX " Failed to reply to message because: %s\n", \
- strerror(-__ret)); \
+ __status.GetErrorMessage().c_str()); \
goto error_label; \
} while (0)
@@ -669,10 +708,10 @@
#define REPLY_MESSAGE_RETURN(message, message_return_code, ...) \
do { \
- int __ret = message.Reply(message_return_code); \
- ALOGE_IF(__ret < 0, \
+ auto __status = message.Reply(message_return_code); \
+ ALOGE_IF(!__status, \
PDX_ERROR_PREFIX " Failed to reply to message because: %s", \
- strerror(-__ret)); \
+ __status.GetErrorMessage().c_str()); \
return __VA_ARGS__; \
} while (0)
@@ -681,19 +720,19 @@
#define REPLY_FD(message, push_fd, error_label) \
do { \
- int __ret = message.ReplyFileDescriptor(push_fd); \
- CHECK_ERROR(__ret < 0, error_label, \
+ auto __status = message.ReplyFileDescriptor(push_fd); \
+ CHECK_ERROR(!__status, error_label, \
PDX_ERROR_PREFIX " Failed to reply to message because: %s\n", \
- strerror(-__ret)); \
+ __status.GetErrorMessage().c_str()); \
goto error_label; \
} while (0)
#define REPLY_FD_RETURN(message, push_fd, ...) \
do { \
- int __ret = message.ReplyFileDescriptor(push_fd); \
- ALOGE_IF(__ret < 0, \
+ auto __status = message.ReplyFileDescriptor(push_fd); \
+ ALOGE_IF(__status < 0, \
PDX_ERROR_PREFIX " Failed to reply to message because: %s", \
- strerror(-__ret)); \
+ __status.GetErrorMessage().c_str()); \
return __VA_ARGS__; \
} while (0)
diff --git a/libs/vr/libpdx/private/pdx/service_endpoint.h b/libs/vr/libpdx/private/pdx/service_endpoint.h
index 613be7c..28bd6bc 100644
--- a/libs/vr/libpdx/private/pdx/service_endpoint.h
+++ b/libs/vr/libpdx/private/pdx/service_endpoint.h
@@ -44,20 +44,20 @@
// Associates a Service instance with an endpoint by setting the service
// context pointer to the address of the Service. Only one Service may be
// associated with a given endpoint.
- virtual int SetService(Service* service) = 0;
+ virtual Status<void> SetService(Service* service) = 0;
// Set the channel context for the given channel.
- virtual int SetChannel(int channel_id, Channel* channel) = 0;
+ virtual Status<void> SetChannel(int channel_id, Channel* channel) = 0;
// Close a channel, signaling the client file object and freeing the channel
// id. Once closed, the client side of the channel always returns the error
// ESHUTDOWN and signals the poll/epoll events POLLHUP and POLLFREE.
- virtual int CloseChannel(int channel_id) = 0;
+ virtual Status<void> CloseChannel(int channel_id) = 0;
// Update the event bits for the given channel (given by id), using the
// given clear and set masks.
- virtual int ModifyChannelEvents(int channel_id, int clear_mask,
- int set_mask) = 0;
+ virtual Status<void> ModifyChannelEvents(int channel_id, int clear_mask,
+ int set_mask) = 0;
// Create a new channel and push it as a file descriptor to the process
// sending the |message|. |flags| may be set to O_NONBLOCK and/or
@@ -77,54 +77,49 @@
virtual Status<int> CheckChannel(const Message* message, ChannelReference ref,
Channel** channel) = 0;
- // The default message handler. It is important that all messages
- // (eventually) get a reply. This method should be called for any unrecognized
- // opcodes or otherwise unhandled messages to prevent erroneous requests from
- // blocking indefinitely.
- virtual int DefaultHandleMessage(const MessageInfo& info) = 0;
-
// Receives a message on the given endpoint file descriptor.
- virtual int MessageReceive(Message* message) = 0;
+ virtual Status<void> MessageReceive(Message* message) = 0;
// Replies to the message with a return code.
- virtual int MessageReply(Message* message, int return_code) = 0;
+ virtual Status<void> MessageReply(Message* message, int return_code) = 0;
// Replies to the message with a file descriptor.
- virtual int MessageReplyFd(Message* message, unsigned int push_fd) = 0;
+ virtual Status<void> MessageReplyFd(Message* message,
+ unsigned int push_fd) = 0;
// Replies to the message with a local channel handle.
- virtual int MessageReplyChannelHandle(Message* message,
- const LocalChannelHandle& handle) = 0;
+ virtual Status<void> MessageReplyChannelHandle(
+ Message* message, const LocalChannelHandle& handle) = 0;
// Replies to the message with a borrowed local channel handle.
- virtual int MessageReplyChannelHandle(
+ virtual Status<void> MessageReplyChannelHandle(
Message* message, const BorrowedChannelHandle& handle) = 0;
// Replies to the message with a remote channel handle.
- virtual int MessageReplyChannelHandle(Message* message,
- const RemoteChannelHandle& handle) = 0;
+ virtual Status<void> MessageReplyChannelHandle(
+ Message* message, const RemoteChannelHandle& handle) = 0;
// Reads message data into an array of memory buffers.
- virtual ssize_t ReadMessageData(Message* message, const iovec* vector,
- size_t vector_length) = 0;
+ virtual Status<size_t> ReadMessageData(Message* message, const iovec* vector,
+ size_t vector_length) = 0;
// Sends reply data for message.
- virtual ssize_t WriteMessageData(Message* message, const iovec* vector,
- size_t vector_length) = 0;
+ virtual Status<size_t> WriteMessageData(Message* message, const iovec* vector,
+ size_t vector_length) = 0;
// Records a file descriptor into the message buffer and returns the remapped
// reference to be sent to the remote process.
- virtual FileReference PushFileHandle(Message* message,
- const LocalHandle& handle) = 0;
- virtual FileReference PushFileHandle(Message* message,
- const BorrowedHandle& handle) = 0;
- virtual FileReference PushFileHandle(Message* message,
- const RemoteHandle& handle) = 0;
- virtual ChannelReference PushChannelHandle(
+ virtual Status<FileReference> PushFileHandle(Message* message,
+ const LocalHandle& handle) = 0;
+ virtual Status<FileReference> PushFileHandle(
+ Message* message, const BorrowedHandle& handle) = 0;
+ virtual Status<FileReference> PushFileHandle(Message* message,
+ const RemoteHandle& handle) = 0;
+ virtual Status<ChannelReference> PushChannelHandle(
Message* message, const LocalChannelHandle& handle) = 0;
- virtual ChannelReference PushChannelHandle(
+ virtual Status<ChannelReference> PushChannelHandle(
Message* message, const BorrowedChannelHandle& handle) = 0;
- virtual ChannelReference PushChannelHandle(
+ virtual Status<ChannelReference> PushChannelHandle(
Message* message, const RemoteChannelHandle& handle) = 0;
// Obtains a file descriptor/channel handle from a message for the given
@@ -140,7 +135,7 @@
// Cancels the endpoint, unblocking any receiver threads waiting for a
// message.
- virtual int Cancel() = 0;
+ virtual Status<void> Cancel() = 0;
};
} // namespace pdx
diff --git a/libs/vr/libpdx/private/pdx/status.h b/libs/vr/libpdx/private/pdx/status.h
index ca2832c..067fe25 100644
--- a/libs/vr/libpdx/private/pdx/status.h
+++ b/libs/vr/libpdx/private/pdx/status.h
@@ -103,6 +103,17 @@
// is not empty nor containing a valid value).
int error() const { return std::max(error_, 0); }
+ // Returns the error code as ErrorStatus object. This is a helper method
+ // to aid in propagation of error codes between Status<T> of different types
+ // as in the following example:
+ // Status<int> foo() {
+ // Status<void> status = bar();
+ // if(!status)
+ // return status.error_status();
+ // return 12;
+ // }
+ inline ErrorStatus error_status() const { return ErrorStatus{error()}; }
+
// Returns the error message associated with error code stored in the object.
// The message is the same as the string returned by strerror(status.error()).
// Can be called only when an error is actually stored (that is, the object
@@ -142,6 +153,7 @@
bool empty() const { return false; }
explicit operator bool() const { return ok(); }
int error() const { return std::max(error_, 0); }
+ inline ErrorStatus error_status() const { return ErrorStatus{error()}; }
std::string GetErrorMessage() const {
std::string message;
if (error_ > 0)
diff --git a/libs/vr/libpdx/private/pdx/utility.h b/libs/vr/libpdx/private/pdx/utility.h
index c8c717c..305c3b8 100644
--- a/libs/vr/libpdx/private/pdx/utility.h
+++ b/libs/vr/libpdx/private/pdx/utility.h
@@ -150,29 +150,29 @@
class NoOpOutputResourceMapper : public OutputResourceMapper {
public:
- FileReference PushFileHandle(const LocalHandle& handle) override {
+ Status<FileReference> PushFileHandle(const LocalHandle& handle) override {
return handle.Get();
}
- FileReference PushFileHandle(const BorrowedHandle& handle) override {
+ Status<FileReference> PushFileHandle(const BorrowedHandle& handle) override {
return handle.Get();
}
- FileReference PushFileHandle(const RemoteHandle& handle) override {
+ Status<FileReference> PushFileHandle(const RemoteHandle& handle) override {
return handle.Get();
}
- ChannelReference PushChannelHandle(
+ Status<ChannelReference> PushChannelHandle(
const LocalChannelHandle& handle) override {
return handle.value();
}
- ChannelReference PushChannelHandle(
+ Status<ChannelReference> PushChannelHandle(
const BorrowedChannelHandle& handle) override {
return handle.value();
}
- ChannelReference PushChannelHandle(
+ Status<ChannelReference> PushChannelHandle(
const RemoteChannelHandle& handle) override {
return handle.value();
}
@@ -278,7 +278,7 @@
OutputResourceMapper* GetOutputResourceMapper() override { return this; }
// OutputResourceMapper
- FileReference PushFileHandle(const LocalHandle& handle) override {
+ Status<FileReference> PushFileHandle(const LocalHandle& handle) override {
if (handle) {
const int ref = file_handles_.size();
file_handles_.push_back(handle.Get());
@@ -288,7 +288,7 @@
}
}
- FileReference PushFileHandle(const BorrowedHandle& handle) override {
+ Status<FileReference> PushFileHandle(const BorrowedHandle& handle) override {
if (handle) {
const int ref = file_handles_.size();
file_handles_.push_back(handle.Get());
@@ -298,11 +298,11 @@
}
}
- FileReference PushFileHandle(const RemoteHandle& handle) override {
+ Status<FileReference> PushFileHandle(const RemoteHandle& handle) override {
return handle.Get();
}
- ChannelReference PushChannelHandle(
+ Status<ChannelReference> PushChannelHandle(
const LocalChannelHandle& handle) override {
if (handle) {
const int ref = file_handles_.size();
@@ -313,7 +313,7 @@
}
}
- ChannelReference PushChannelHandle(
+ Status<ChannelReference> PushChannelHandle(
const BorrowedChannelHandle& handle) override {
if (handle) {
const int ref = file_handles_.size();
@@ -324,7 +324,7 @@
}
}
- ChannelReference PushChannelHandle(
+ Status<ChannelReference> PushChannelHandle(
const RemoteChannelHandle& handle) override {
return handle.value();
}
diff --git a/libs/vr/libpdx/service.cpp b/libs/vr/libpdx/service.cpp
index daf9af8..fab4770 100644
--- a/libs/vr/libpdx/service.cpp
+++ b/libs/vr/libpdx/service.cpp
@@ -9,7 +9,6 @@
#include <cstdint>
#include <pdx/trace.h>
-#include "errno_guard.h"
#define TRACE 0
@@ -60,7 +59,7 @@
"ERROR: Service \"%s\" failed to reply to message: op=%d pid=%d "
"cid=%d\n",
svc->name_.c_str(), info_.op, info_.pid, info_.cid);
- svc->endpoint()->DefaultHandleMessage(info_);
+ svc->DefaultHandleMessage(*this);
}
svc->endpoint()->FreeMessageState(state_);
}
@@ -77,112 +76,138 @@
return ImpulseBegin() + (IsImpulse() ? GetSendLength() : 0);
}
-ssize_t Message::ReadVector(const struct iovec* vector, size_t vector_length) {
+Status<size_t> Message::ReadVector(const struct iovec* vector,
+ size_t vector_length) {
PDX_TRACE_NAME("Message::ReadVector");
if (auto svc = service_.lock()) {
- ErrnoGuard errno_guard;
- const ssize_t ret =
- svc->endpoint()->ReadMessageData(this, vector, vector_length);
- return ReturnCodeOrError(ret);
+ return svc->endpoint()->ReadMessageData(this, vector, vector_length);
} else {
- return -ESHUTDOWN;
+ return ErrorStatus{ESHUTDOWN};
}
}
-ssize_t Message::Read(void* buffer, size_t length) {
+Status<void> Message::ReadVectorAll(const struct iovec* vector,
+ size_t vector_length) {
+ PDX_TRACE_NAME("Message::ReadVectorAll");
+ if (auto svc = service_.lock()) {
+ const auto status =
+ svc->endpoint()->ReadMessageData(this, vector, vector_length);
+ if (!status)
+ return status.error_status();
+ size_t size_to_read = 0;
+ for (size_t i = 0; i < vector_length; i++)
+ size_to_read += vector[i].iov_len;
+ if (status.get() < size_to_read)
+ return ErrorStatus{EIO};
+ return {};
+ } else {
+ return ErrorStatus{ESHUTDOWN};
+ }
+}
+
+Status<size_t> Message::Read(void* buffer, size_t length) {
PDX_TRACE_NAME("Message::Read");
if (auto svc = service_.lock()) {
- ErrnoGuard errno_guard;
const struct iovec vector = {buffer, length};
- const ssize_t ret = svc->endpoint()->ReadMessageData(this, &vector, 1);
- return ReturnCodeOrError(ret);
+ return svc->endpoint()->ReadMessageData(this, &vector, 1);
} else {
- return -ESHUTDOWN;
+ return ErrorStatus{ESHUTDOWN};
}
}
-ssize_t Message::WriteVector(const struct iovec* vector, size_t vector_length) {
+Status<size_t> Message::WriteVector(const struct iovec* vector,
+ size_t vector_length) {
PDX_TRACE_NAME("Message::WriteVector");
if (auto svc = service_.lock()) {
- ErrnoGuard errno_guard;
- const ssize_t ret =
- svc->endpoint()->WriteMessageData(this, vector, vector_length);
- return ReturnCodeOrError(ret);
+ return svc->endpoint()->WriteMessageData(this, vector, vector_length);
} else {
- return -ESHUTDOWN;
+ return ErrorStatus{ESHUTDOWN};
}
}
-ssize_t Message::Write(const void* buffer, size_t length) {
+Status<void> Message::WriteVectorAll(const struct iovec* vector,
+ size_t vector_length) {
+ PDX_TRACE_NAME("Message::WriteVector");
+ if (auto svc = service_.lock()) {
+ const auto status =
+ svc->endpoint()->WriteMessageData(this, vector, vector_length);
+ if (!status)
+ return status.error_status();
+ size_t size_to_write = 0;
+ for (size_t i = 0; i < vector_length; i++)
+ size_to_write += vector[i].iov_len;
+ if (status.get() < size_to_write)
+ return ErrorStatus{EIO};
+ return {};
+ } else {
+ return ErrorStatus{ESHUTDOWN};
+ }
+}
+
+Status<size_t> Message::Write(const void* buffer, size_t length) {
PDX_TRACE_NAME("Message::Write");
if (auto svc = service_.lock()) {
- ErrnoGuard errno_guard;
const struct iovec vector = {const_cast<void*>(buffer), length};
- const ssize_t ret = svc->endpoint()->WriteMessageData(this, &vector, 1);
- return ReturnCodeOrError(ret);
+ return svc->endpoint()->WriteMessageData(this, &vector, 1);
} else {
- return -ESHUTDOWN;
+ return ErrorStatus{ESHUTDOWN};
}
}
-FileReference Message::PushFileHandle(const LocalHandle& handle) {
+Status<FileReference> Message::PushFileHandle(const LocalHandle& handle) {
PDX_TRACE_NAME("Message::PushFileHandle");
if (auto svc = service_.lock()) {
- ErrnoGuard errno_guard;
- return ReturnCodeOrError(svc->endpoint()->PushFileHandle(this, handle));
+ return svc->endpoint()->PushFileHandle(this, handle);
} else {
- return -ESHUTDOWN;
+ return ErrorStatus{ESHUTDOWN};
}
}
-FileReference Message::PushFileHandle(const BorrowedHandle& handle) {
+Status<FileReference> Message::PushFileHandle(const BorrowedHandle& handle) {
PDX_TRACE_NAME("Message::PushFileHandle");
if (auto svc = service_.lock()) {
- ErrnoGuard errno_guard;
- return ReturnCodeOrError(svc->endpoint()->PushFileHandle(this, handle));
+ return svc->endpoint()->PushFileHandle(this, handle);
} else {
- return -ESHUTDOWN;
+ return ErrorStatus{ESHUTDOWN};
}
}
-FileReference Message::PushFileHandle(const RemoteHandle& handle) {
+Status<FileReference> Message::PushFileHandle(const RemoteHandle& handle) {
PDX_TRACE_NAME("Message::PushFileHandle");
if (auto svc = service_.lock()) {
- ErrnoGuard errno_guard;
- return ReturnCodeOrError(svc->endpoint()->PushFileHandle(this, handle));
+ return svc->endpoint()->PushFileHandle(this, handle);
} else {
- return -ESHUTDOWN;
+ return ErrorStatus{ESHUTDOWN};
}
}
-ChannelReference Message::PushChannelHandle(const LocalChannelHandle& handle) {
+Status<ChannelReference> Message::PushChannelHandle(
+ const LocalChannelHandle& handle) {
PDX_TRACE_NAME("Message::PushChannelHandle");
if (auto svc = service_.lock()) {
- ErrnoGuard errno_guard;
- return ReturnCodeOrError(svc->endpoint()->PushChannelHandle(this, handle));
+ return svc->endpoint()->PushChannelHandle(this, handle);
} else {
- return -ESHUTDOWN;
+ return ErrorStatus{ESHUTDOWN};
}
}
-ChannelReference Message::PushChannelHandle(
+Status<ChannelReference> Message::PushChannelHandle(
const BorrowedChannelHandle& handle) {
PDX_TRACE_NAME("Message::PushChannelHandle");
if (auto svc = service_.lock()) {
- ErrnoGuard errno_guard;
- return ReturnCodeOrError(svc->endpoint()->PushChannelHandle(this, handle));
+ return svc->endpoint()->PushChannelHandle(this, handle);
} else {
- return -ESHUTDOWN;
+ return ErrorStatus{ESHUTDOWN};
}
}
-ChannelReference Message::PushChannelHandle(const RemoteChannelHandle& handle) {
+Status<ChannelReference> Message::PushChannelHandle(
+ const RemoteChannelHandle& handle) {
PDX_TRACE_NAME("Message::PushChannelHandle");
if (auto svc = service_.lock()) {
- ErrnoGuard errno_guard;
- return ReturnCodeOrError(svc->endpoint()->PushChannelHandle(this, handle));
+ return svc->endpoint()->PushChannelHandle(this, handle);
} else {
- return -ESHUTDOWN;
+ return ErrorStatus{ESHUTDOWN};
}
}
@@ -193,7 +218,6 @@
return false;
if (ref >= 0) {
- ErrnoGuard errno_guard;
*handle = svc->endpoint()->GetFileHandle(this, ref);
if (!handle->IsValid())
return false;
@@ -211,7 +235,6 @@
return false;
if (ref >= 0) {
- ErrnoGuard errno_guard;
*handle = svc->endpoint()->GetChannelHandle(this, ref);
if (!handle->valid())
return false;
@@ -221,141 +244,137 @@
return true;
}
-int Message::Reply(int return_code) {
+Status<void> Message::Reply(int return_code) {
PDX_TRACE_NAME("Message::Reply");
auto svc = service_.lock();
if (!replied_ && svc) {
- ErrnoGuard errno_guard;
- const int ret = svc->endpoint()->MessageReply(this, return_code);
- replied_ = ret == 0;
- return ReturnCodeOrError(ret);
+ const auto ret = svc->endpoint()->MessageReply(this, return_code);
+ replied_ = ret.ok();
+ return ret;
} else {
- return -EINVAL;
+ return ErrorStatus{EINVAL};
}
}
-int Message::ReplyFileDescriptor(unsigned int fd) {
+Status<void> Message::ReplyFileDescriptor(unsigned int fd) {
PDX_TRACE_NAME("Message::ReplyFileDescriptor");
auto svc = service_.lock();
if (!replied_ && svc) {
- ErrnoGuard errno_guard;
- const int ret = svc->endpoint()->MessageReplyFd(this, fd);
- replied_ = ret == 0;
- return ReturnCodeOrError(ret);
+ const auto ret = svc->endpoint()->MessageReplyFd(this, fd);
+ replied_ = ret.ok();
+ return ret;
} else {
- return -EINVAL;
+ return ErrorStatus{EINVAL};
}
}
-int Message::ReplyError(unsigned error) {
+Status<void> Message::ReplyError(unsigned int error) {
PDX_TRACE_NAME("Message::ReplyError");
auto svc = service_.lock();
if (!replied_ && svc) {
- ErrnoGuard errno_guard;
- const int ret = svc->endpoint()->MessageReply(this, -error);
- replied_ = ret == 0;
- return ReturnCodeOrError(ret);
+ const auto ret =
+ svc->endpoint()->MessageReply(this, -static_cast<int>(error));
+ replied_ = ret.ok();
+ return ret;
} else {
- return -EINVAL;
+ return ErrorStatus{EINVAL};
}
}
-int Message::Reply(const LocalHandle& handle) {
+Status<void> Message::Reply(const LocalHandle& handle) {
PDX_TRACE_NAME("Message::ReplyFileHandle");
auto svc = service_.lock();
if (!replied_ && svc) {
- ErrnoGuard errno_guard;
- int ret;
+ Status<void> ret;
if (handle)
ret = svc->endpoint()->MessageReplyFd(this, handle.Get());
else
ret = svc->endpoint()->MessageReply(this, handle.Get());
- replied_ = ret == 0;
- return ReturnCodeOrError(ret);
+ replied_ = ret.ok();
+ return ret;
} else {
- return -EINVAL;
+ return ErrorStatus{EINVAL};
}
}
-int Message::Reply(const BorrowedHandle& handle) {
+Status<void> Message::Reply(const BorrowedHandle& handle) {
PDX_TRACE_NAME("Message::ReplyFileHandle");
auto svc = service_.lock();
if (!replied_ && svc) {
- ErrnoGuard errno_guard;
- int ret;
+ Status<void> ret;
if (handle)
ret = svc->endpoint()->MessageReplyFd(this, handle.Get());
else
ret = svc->endpoint()->MessageReply(this, handle.Get());
- replied_ = ret == 0;
- return ReturnCodeOrError(ret);
+ replied_ = ret.ok();
+ return ret;
} else {
- return -EINVAL;
+ return ErrorStatus{EINVAL};
}
}
-int Message::Reply(const RemoteHandle& handle) {
+Status<void> Message::Reply(const RemoteHandle& handle) {
PDX_TRACE_NAME("Message::ReplyFileHandle");
auto svc = service_.lock();
if (!replied_ && svc) {
- ErrnoGuard errno_guard;
- const int ret = svc->endpoint()->MessageReply(this, handle.Get());
- replied_ = ret == 0;
- return ReturnCodeOrError(ret);
+ Status<void> ret;
+
+ if (handle)
+ ret = svc->endpoint()->MessageReply(this, handle.Get());
+ else
+ ret = svc->endpoint()->MessageReply(this, handle.Get());
+
+ replied_ = ret.ok();
+ return ret;
} else {
- return -EINVAL;
+ return ErrorStatus{EINVAL};
}
}
-int Message::Reply(const LocalChannelHandle& handle) {
+Status<void> Message::Reply(const LocalChannelHandle& handle) {
auto svc = service_.lock();
if (!replied_ && svc) {
- ErrnoGuard errno_guard;
- const int ret = svc->endpoint()->MessageReplyChannelHandle(this, handle);
- replied_ = ret == 0;
- return ReturnCodeOrError(ret);
+ const auto ret = svc->endpoint()->MessageReplyChannelHandle(this, handle);
+ replied_ = ret.ok();
+ return ret;
} else {
- return -EINVAL;
+ return ErrorStatus{EINVAL};
}
}
-int Message::Reply(const BorrowedChannelHandle& handle) {
+Status<void> Message::Reply(const BorrowedChannelHandle& handle) {
auto svc = service_.lock();
if (!replied_ && svc) {
- ErrnoGuard errno_guard;
- const int ret = svc->endpoint()->MessageReplyChannelHandle(this, handle);
- replied_ = ret == 0;
- return ReturnCodeOrError(ret);
+ const auto ret = svc->endpoint()->MessageReplyChannelHandle(this, handle);
+ replied_ = ret.ok();
+ return ret;
} else {
- return -EINVAL;
+ return ErrorStatus{EINVAL};
}
}
-int Message::Reply(const RemoteChannelHandle& handle) {
+Status<void> Message::Reply(const RemoteChannelHandle& handle) {
auto svc = service_.lock();
if (!replied_ && svc) {
- ErrnoGuard errno_guard;
- const int ret = svc->endpoint()->MessageReplyChannelHandle(this, handle);
- replied_ = ret == 0;
- return ReturnCodeOrError(ret);
+ const auto ret = svc->endpoint()->MessageReplyChannelHandle(this, handle);
+ replied_ = ret.ok();
+ return ret;
} else {
- return -EINVAL;
+ return ErrorStatus{EINVAL};
}
}
-int Message::ModifyChannelEvents(int clear_mask, int set_mask) {
+Status<void> Message::ModifyChannelEvents(int clear_mask, int set_mask) {
PDX_TRACE_NAME("Message::ModifyChannelEvents");
if (auto svc = service_.lock()) {
- ErrnoGuard errno_guard;
- const int ret =
- svc->endpoint()->ModifyChannelEvents(info_.cid, clear_mask, set_mask);
- return ReturnCodeOrError(ret);
+ return svc->endpoint()->ModifyChannelEvents(info_.cid, clear_mask,
+ set_mask);
} else {
- return -ESHUTDOWN;
+ return ErrorStatus{ESHUTDOWN};
}
}
@@ -416,11 +435,12 @@
std::shared_ptr<Channel> Message::GetChannel() const { return channel_.lock(); }
-void Message::SetChannel(const std::shared_ptr<Channel>& chan) {
+Status<void> Message::SetChannel(const std::shared_ptr<Channel>& chan) {
channel_ = chan;
-
+ Status<void> status;
if (auto svc = service_.lock())
- svc->SetChannel(info_.cid, chan);
+ status = svc->SetChannel(info_.cid, chan);
+ return status;
}
std::shared_ptr<Service> Message::GetService() const { return service_.lock(); }
@@ -432,16 +452,16 @@
if (!endpoint_)
return;
- const int ret = endpoint_->SetService(this);
- ALOGE_IF(ret < 0, "Failed to set service context because: %s",
- strerror(-ret));
+ const auto status = endpoint_->SetService(this);
+ ALOGE_IF(!status, "Failed to set service context because: %s",
+ status.GetErrorMessage().c_str());
}
Service::~Service() {
if (endpoint_) {
- const int ret = endpoint_->SetService(nullptr);
- ALOGE_IF(ret < 0, "Failed to clear service context because: %s",
- strerror(-ret));
+ const auto status = endpoint_->SetService(nullptr);
+ ALOGE_IF(!status, "Failed to clear service context because: %s",
+ status.GetErrorMessage().c_str());
}
}
@@ -459,32 +479,28 @@
void Service::OnChannelClose(Message& /*message*/,
const std::shared_ptr<Channel>& /*channel*/) {}
-int Service::SetChannel(int channel_id,
- const std::shared_ptr<Channel>& channel) {
+Status<void> Service::SetChannel(int channel_id,
+ const std::shared_ptr<Channel>& channel) {
PDX_TRACE_NAME("Service::SetChannel");
- ErrnoGuard errno_guard;
std::lock_guard<std::mutex> autolock(channels_mutex_);
- const int ret = endpoint_->SetChannel(channel_id, channel.get());
- if (ret == -1) {
+ const auto status = endpoint_->SetChannel(channel_id, channel.get());
+ if (!status) {
ALOGE("%s::SetChannel: Failed to set channel context: %s\n", name_.c_str(),
- strerror(errno));
+ status.GetErrorMessage().c_str());
// It's possible someone mucked with things behind our back by calling the C
// API directly. Since we know the channel id isn't valid, make sure we
// don't have it in the channels map.
- if (errno == ENOENT)
+ if (status.error() == ENOENT)
channels_.erase(channel_id);
-
- return ReturnCodeOrError(ret);
+ } else {
+ if (channel != nullptr)
+ channels_[channel_id] = channel;
+ else
+ channels_.erase(channel_id);
}
-
- if (channel != nullptr)
- channels_[channel_id] = channel;
- else
- channels_.erase(channel_id);
-
- return ret;
+ return status;
}
std::shared_ptr<Channel> Service::GetChannel(int channel_id) const {
@@ -498,21 +514,21 @@
return nullptr;
}
-int Service::CloseChannel(int channel_id) {
+Status<void> Service::CloseChannel(int channel_id) {
PDX_TRACE_NAME("Service::CloseChannel");
- ErrnoGuard errno_guard;
std::lock_guard<std::mutex> autolock(channels_mutex_);
- const int ret = endpoint_->CloseChannel(channel_id);
+ const auto status = endpoint_->CloseChannel(channel_id);
// Always erase the map entry, in case someone mucked with things behind our
// back using the C API directly.
channels_.erase(channel_id);
- return ReturnCodeOrError(ret);
+ return status;
}
-int Service::ModifyChannelEvents(int channel_id, int clear_mask, int set_mask) {
+Status<void> Service::ModifyChannelEvents(int channel_id, int clear_mask,
+ int set_mask) {
PDX_TRACE_NAME("Service::ModifyChannelEvents");
return endpoint_->ModifyChannelEvents(channel_id, clear_mask, set_mask);
}
@@ -521,7 +537,6 @@
Message* message, int flags, const std::shared_ptr<Channel>& channel,
int* channel_id) {
PDX_TRACE_NAME("Service::PushChannel");
- ErrnoGuard errno_guard;
std::lock_guard<std::mutex> autolock(channels_mutex_);
@@ -542,7 +557,6 @@
Status<int> Service::CheckChannel(const Message* message, ChannelReference ref,
std::shared_ptr<Channel>* channel) const {
PDX_TRACE_NAME("Service::CheckChannel");
- ErrnoGuard errno_guard;
// Synchronization to maintain consistency between the kernel's channel
// context pointer and the userspace channels_ map. Other threads may attempt
@@ -565,13 +579,13 @@
std::string Service::DumpState(size_t /*max_length*/) { return ""; }
-int Service::HandleMessage(Message& message) {
+Status<void> Service::HandleMessage(Message& message) {
return DefaultHandleMessage(message);
}
void Service::HandleImpulse(Message& /*impulse*/) {}
-bool Service::HandleSystemMessage(Message& message) {
+Status<void> Service::HandleSystemMessage(Message& message) {
const MessageInfo& info = message.GetInfo();
switch (info.op) {
@@ -579,8 +593,7 @@
ALOGD("%s::OnChannelOpen: pid=%d cid=%d\n", name_.c_str(), info.pid,
info.cid);
message.SetChannel(OnChannelOpen(message));
- message.Reply(0);
- return true;
+ return message.Reply(0);
}
case opcodes::CHANNEL_CLOSE: {
@@ -588,8 +601,7 @@
info.cid);
OnChannelClose(message, Channel::GetFromMessageInfo(info));
message.SetChannel(nullptr);
- message.Reply(0);
- return true;
+ return message.Reply(0);
}
case opcodes::REPORT_SYSPROP_CHANGE:
@@ -597,8 +609,7 @@
info.pid, info.cid);
OnSysPropChange();
android::report_sysprop_change();
- message.Reply(0);
- return true;
+ return message.Reply(0);
case opcodes::DUMP_STATE: {
ALOGD("%s:DUMP_STATE: pid=%d cid=%d\n", name_.c_str(), info.pid,
@@ -607,21 +618,20 @@
const size_t response_size = response.size() < message.GetReceiveLength()
? response.size()
: message.GetReceiveLength();
- const ssize_t bytes_written =
+ const Status<size_t> status =
message.Write(response.data(), response_size);
- if (bytes_written < static_cast<ssize_t>(response_size))
- message.ReplyError(EIO);
+ if (status && status.get() < response_size)
+ return message.ReplyError(EIO);
else
- message.Reply(bytes_written);
- return true;
+ return message.Reply(status);
}
default:
- return false;
+ return ErrorStatus{EOPNOTSUPP};
}
}
-int Service::DefaultHandleMessage(Message& message) {
+Status<void> Service::DefaultHandleMessage(Message& message) {
const MessageInfo& info = message.GetInfo();
ALOGD_IF(TRACE, "Service::DefaultHandleMessage: pid=%d cid=%d op=%d\n",
@@ -632,23 +642,21 @@
case opcodes::CHANNEL_CLOSE:
case opcodes::REPORT_SYSPROP_CHANGE:
case opcodes::DUMP_STATE:
- HandleSystemMessage(message);
- return 0;
+ return HandleSystemMessage(message);
default:
- return message.ReplyError(ENOTSUP);
+ return message.ReplyError(EOPNOTSUPP);
}
}
void Service::OnSysPropChange() {}
-int Service::ReceiveAndDispatch() {
- ErrnoGuard errno_guard;
+Status<void> Service::ReceiveAndDispatch() {
Message message;
- const int ret = endpoint_->MessageReceive(&message);
- if (ret < 0) {
- ALOGE("Failed to receive message: %s\n", strerror(errno));
- return ReturnCodeOrError(ret);
+ const auto status = endpoint_->MessageReceive(&message);
+ if (!status) {
+ ALOGE("Failed to receive message: %s\n", status.GetErrorMessage().c_str());
+ return status;
}
std::shared_ptr<Service> service = message.GetService();
@@ -657,24 +665,20 @@
ALOGE("Service::ReceiveAndDispatch: service context is NULL!!!\n");
// Don't block the sender indefinitely in this error case.
endpoint_->MessageReply(&message, -EINVAL);
- return -EINVAL;
+ return ErrorStatus{EINVAL};
}
if (message.IsImpulse()) {
service->HandleImpulse(message);
- return 0;
+ return {};
} else if (service->HandleSystemMessage(message)) {
- return 0;
+ return {};
} else {
return service->HandleMessage(message);
}
}
-int Service::Cancel() {
- ErrnoGuard errno_guard;
- const int ret = endpoint_->Cancel();
- return ReturnCodeOrError(ret);
-}
+Status<void> Service::Cancel() { return endpoint_->Cancel(); }
} // namespace pdx
} // namespace android
diff --git a/libs/vr/libpdx/service_tests.cpp b/libs/vr/libpdx/service_tests.cpp
index fc0c8db..c7412b7 100644
--- a/libs/vr/libpdx/service_tests.cpp
+++ b/libs/vr/libpdx/service_tests.cpp
@@ -30,7 +30,6 @@
using testing::Ref;
using testing::Return;
using testing::SetArgPointee;
-using testing::SetErrnoAndReturn;
using testing::WithArg;
using testing::WithoutArgs;
using testing::_;
@@ -91,7 +90,7 @@
MOCK_METHOD1(OnChannelOpen, std::shared_ptr<Channel>(Message& message));
MOCK_METHOD2(OnChannelClose,
void(Message& message, const std::shared_ptr<Channel>& channel));
- MOCK_METHOD1(HandleMessage, int(Message& message));
+ MOCK_METHOD1(HandleMessage, Status<void>(Message& message));
MOCK_METHOD1(HandleImpulse, void(Message& impulse));
MOCK_METHOD0(OnSysPropChange, void());
MOCK_METHOD1(DumpState, std::string(size_t max_length));
@@ -101,7 +100,9 @@
public:
ServiceTest() {
auto endpoint = std::make_unique<testing::StrictMock<MockEndpoint>>();
- EXPECT_CALL(*endpoint, SetService(_)).Times(2).WillRepeatedly(Return(0));
+ EXPECT_CALL(*endpoint, SetService(_))
+ .Times(2)
+ .WillRepeatedly(Return(Status<void>{}));
service_ = std::make_shared<MockService>("MockSvc", std::move(endpoint));
}
@@ -134,7 +135,8 @@
}
void ExpectDefaultHandleMessage() {
- EXPECT_CALL(*endpoint(), DefaultHandleMessage(_));
+ EXPECT_CALL(*endpoint(), MessageReply(_, -EOPNOTSUPP))
+ .WillOnce(Return(Status<void>{}));
}
std::shared_ptr<MockService> service_;
@@ -222,10 +224,11 @@
auto channel = std::make_shared<Channel>();
EXPECT_CALL(*service_, OnChannelOpen(Ref(message))).WillOnce(Return(channel));
EXPECT_CALL(*endpoint(), SetChannel(kTestCid, channel.get()))
- .WillOnce(Return(0));
- EXPECT_CALL(*endpoint(), MessageReply(&message, 0)).WillOnce(Return(0));
+ .WillOnce(Return(Status<void>{}));
+ EXPECT_CALL(*endpoint(), MessageReply(&message, 0))
+ .WillOnce(Return(Status<void>{}));
- EXPECT_EQ(0, service_->Service::HandleMessage(message));
+ EXPECT_TRUE(service_->Service::HandleMessage(message));
}
TEST_F(ServiceTest, HandleMessageChannelClose) {
@@ -237,10 +240,12 @@
Message message{info};
EXPECT_CALL(*service_, OnChannelClose(Ref(message), channel));
- EXPECT_CALL(*endpoint(), SetChannel(kTestCid, nullptr)).WillOnce(Return(0));
- EXPECT_CALL(*endpoint(), MessageReply(&message, 0)).WillOnce(Return(0));
+ EXPECT_CALL(*endpoint(), SetChannel(kTestCid, nullptr))
+ .WillOnce(Return(Status<void>{}));
+ EXPECT_CALL(*endpoint(), MessageReply(&message, 0))
+ .WillOnce(Return(Status<void>{}));
- EXPECT_EQ(0, service_->Service::HandleMessage(message));
+ EXPECT_TRUE(service_->Service::HandleMessage(message));
}
TEST_F(ServiceTest, HandleMessageOnSysPropChange) {
@@ -250,9 +255,10 @@
Message message{info};
EXPECT_CALL(*service_, OnSysPropChange());
- EXPECT_CALL(*endpoint(), MessageReply(&message, 0)).WillOnce(Return(0));
+ EXPECT_CALL(*endpoint(), MessageReply(&message, 0))
+ .WillOnce(Return(Status<void>{}));
- EXPECT_EQ(0, service_->Service::HandleMessage(message));
+ EXPECT_TRUE(service_->Service::HandleMessage(message));
}
TEST_F(ServiceTest, HandleMessageOnDumpState) {
@@ -270,9 +276,9 @@
WriteMessageData(&message, IoVecDataMatcher(IoVecData{kReply}), 1))
.WillOnce(Return(kReply.size()));
EXPECT_CALL(*endpoint(), MessageReply(&message, kReply.size()))
- .WillOnce(Return(0));
+ .WillOnce(Return(Status<void>{}));
- EXPECT_EQ(0, service_->Service::HandleMessage(message));
+ EXPECT_TRUE(service_->Service::HandleMessage(message));
}
TEST_F(ServiceTest, HandleMessageOnDumpStateTooLarge) {
@@ -291,9 +297,9 @@
WriteMessageData(&message, IoVecDataMatcher(IoVecData{kActualReply}), 1))
.WillOnce(Return(kActualReply.size()));
EXPECT_CALL(*endpoint(), MessageReply(&message, kActualReply.size()))
- .WillOnce(Return(0));
+ .WillOnce(Return(Status<void>{}));
- EXPECT_EQ(0, service_->Service::HandleMessage(message));
+ EXPECT_TRUE(service_->Service::HandleMessage(message));
}
TEST_F(ServiceTest, HandleMessageOnDumpStateFail) {
@@ -310,9 +316,10 @@
*endpoint(),
WriteMessageData(&message, IoVecDataMatcher(IoVecData{kReply}), 1))
.WillOnce(Return(1));
- EXPECT_CALL(*endpoint(), MessageReply(&message, -EIO)).WillOnce(Return(0));
+ EXPECT_CALL(*endpoint(), MessageReply(&message, -EIO))
+ .WillOnce(Return(Status<void>{}));
- EXPECT_EQ(0, service_->Service::HandleMessage(message));
+ EXPECT_TRUE(service_->Service::HandleMessage(message));
}
TEST_F(ServiceTest, HandleMessageCustom) {
@@ -320,10 +327,10 @@
SetupMessageInfoAndDefaultExpectations(&info, kTestOp);
Message message{info};
- EXPECT_CALL(*endpoint(), MessageReply(&message, -ENOTSUP))
- .WillOnce(Return(0));
+ EXPECT_CALL(*endpoint(), MessageReply(&message, -EOPNOTSUPP))
+ .WillOnce(Return(Status<void>{}));
- EXPECT_EQ(0, service_->Service::HandleMessage(message));
+ EXPECT_TRUE(service_->Service::HandleMessage(message));
}
TEST_F(ServiceTest, ReplyMessageWithoutService) {
@@ -337,7 +344,7 @@
service_.reset();
EXPECT_TRUE(message.IsServiceExpired());
- EXPECT_EQ(-EINVAL, message.Reply(12));
+ EXPECT_EQ(EINVAL, message.Reply(12).error());
}
TEST_F(ServiceTest, ReceiveAndDispatchMessage) {
@@ -345,33 +352,33 @@
SetupMessageInfoAndDefaultExpectations(&info, kTestOp);
ExpectDefaultHandleMessage();
- auto on_receive = [&info](Message* message) {
+ auto on_receive = [&info](Message* message) -> Status<void> {
*message = Message{info};
- return 0;
+ return {};
};
EXPECT_CALL(*endpoint(), MessageReceive(_)).WillOnce(Invoke(on_receive));
- EXPECT_CALL(*service_, HandleMessage(_)).WillOnce(Return(0));
+ EXPECT_CALL(*service_, HandleMessage(_)).WillOnce(Return(Status<void>{}));
- EXPECT_EQ(0, service_->ReceiveAndDispatch());
+ EXPECT_TRUE(service_->ReceiveAndDispatch());
}
TEST_F(ServiceTest, ReceiveAndDispatchImpulse) {
MessageInfo info;
SetupMessageInfoAndDefaultExpectations(&info, kTestOp, true);
- auto on_receive = [&info](Message* message) {
+ auto on_receive = [&info](Message* message) -> Status<void> {
*message = Message{info};
- return 0;
+ return {};
};
EXPECT_CALL(*endpoint(), MessageReceive(_)).WillOnce(Invoke(on_receive));
EXPECT_CALL(*service_, HandleImpulse(_));
- EXPECT_EQ(0, service_->ReceiveAndDispatch());
+ EXPECT_TRUE(service_->ReceiveAndDispatch());
}
TEST_F(ServiceTest, Cancel) {
- EXPECT_CALL(*endpoint(), Cancel()).WillOnce(Return(0));
- EXPECT_EQ(0, service_->Cancel());
+ EXPECT_CALL(*endpoint(), Cancel()).WillOnce(Return(Status<void>{}));
+ EXPECT_TRUE(service_->Cancel());
}
///////////////////////////////////////////////////////////////////////////////
@@ -380,85 +387,85 @@
TEST_F(ServiceMessageTest, Reply) {
EXPECT_CALL(*endpoint(), MessageReply(message_.get(), 12))
- .WillOnce(Return(0));
+ .WillOnce(Return(Status<void>{}));
EXPECT_FALSE(message_->replied());
- EXPECT_EQ(0, message_->Reply(12));
+ EXPECT_TRUE(message_->Reply(12));
EXPECT_TRUE(message_->replied());
- EXPECT_EQ(-EINVAL, message_->Reply(12)); // Already replied.
+ EXPECT_EQ(EINVAL, message_->Reply(12).error()); // Already replied.
}
TEST_F(ServiceMessageTest, ReplyFail) {
EXPECT_CALL(*endpoint(), MessageReply(message_.get(), 12))
- .WillOnce(SetErrnoAndReturn(EIO, -1));
- EXPECT_EQ(-EIO, message_->Reply(12));
+ .WillOnce(Return(ErrorStatus{EIO}));
+ EXPECT_EQ(EIO, message_->Reply(12).error());
ExpectDefaultHandleMessage();
}
TEST_F(ServiceMessageTest, ReplyError) {
EXPECT_CALL(*endpoint(), MessageReply(message_.get(), -12))
- .WillOnce(Return(0));
- EXPECT_EQ(0, message_->ReplyError(12));
+ .WillOnce(Return(Status<void>{}));
+ EXPECT_TRUE(message_->ReplyError(12));
}
TEST_F(ServiceMessageTest, ReplyFileDescriptor) {
EXPECT_CALL(*endpoint(), MessageReplyFd(message_.get(), 5))
- .WillOnce(Return(0));
- EXPECT_EQ(0, message_->ReplyFileDescriptor(5));
+ .WillOnce(Return(Status<void>{}));
+ EXPECT_TRUE(message_->ReplyFileDescriptor(5));
}
TEST_F(ServiceMessageTest, ReplyLocalFileHandle) {
const int kFakeFd = 12345;
LocalHandle handle{kFakeFd};
EXPECT_CALL(*endpoint(), MessageReplyFd(message_.get(), kFakeFd))
- .WillOnce(Return(0));
- EXPECT_EQ(0, message_->Reply(handle));
+ .WillOnce(Return(Status<void>{}));
+ EXPECT_TRUE(message_->Reply(handle));
handle.Release(); // Make sure we do not close the fake file descriptor.
}
TEST_F(ServiceMessageTest, ReplyLocalFileHandleError) {
LocalHandle handle{-EINVAL};
EXPECT_CALL(*endpoint(), MessageReply(message_.get(), -EINVAL))
- .WillOnce(Return(0));
- EXPECT_EQ(0, message_->Reply(handle));
+ .WillOnce(Return(Status<void>{}));
+ EXPECT_TRUE(message_->Reply(handle));
}
TEST_F(ServiceMessageTest, ReplyBorrowedFileHandle) {
const int kFakeFd = 12345;
BorrowedHandle handle{kFakeFd};
EXPECT_CALL(*endpoint(), MessageReplyFd(message_.get(), kFakeFd))
- .WillOnce(Return(0));
- EXPECT_EQ(0, message_->Reply(handle));
+ .WillOnce(Return(Status<void>{}));
+ EXPECT_TRUE(message_->Reply(handle));
}
TEST_F(ServiceMessageTest, ReplyBorrowedFileHandleError) {
BorrowedHandle handle{-EACCES};
EXPECT_CALL(*endpoint(), MessageReply(message_.get(), -EACCES))
- .WillOnce(Return(0));
- EXPECT_EQ(0, message_->Reply(handle));
+ .WillOnce(Return(Status<void>{}));
+ EXPECT_TRUE(message_->Reply(handle));
}
TEST_F(ServiceMessageTest, ReplyRemoteFileHandle) {
RemoteHandle handle{123};
EXPECT_CALL(*endpoint(), MessageReply(message_.get(), handle.Get()))
- .WillOnce(Return(0));
- EXPECT_EQ(0, message_->Reply(handle));
+ .WillOnce(Return(Status<void>{}));
+ EXPECT_TRUE(message_->Reply(handle));
}
TEST_F(ServiceMessageTest, ReplyRemoteFileHandleError) {
RemoteHandle handle{-EIO};
EXPECT_CALL(*endpoint(), MessageReply(message_.get(), -EIO))
- .WillOnce(Return(0));
- EXPECT_EQ(0, message_->Reply(handle));
+ .WillOnce(Return(Status<void>{}));
+ EXPECT_TRUE(message_->Reply(handle));
}
TEST_F(ServiceMessageTest, ReplyLocalChannelHandle) {
LocalChannelHandle handle{nullptr, 12345};
EXPECT_CALL(*endpoint(), MessageReplyChannelHandle(
message_.get(), A<const LocalChannelHandle&>()))
- .WillOnce(Return(0));
- EXPECT_EQ(0, message_->Reply(handle));
+ .WillOnce(Return(Status<void>{}));
+ EXPECT_TRUE(message_->Reply(handle));
}
TEST_F(ServiceMessageTest, ReplyBorrowedChannelHandle) {
@@ -466,30 +473,30 @@
EXPECT_CALL(*endpoint(),
MessageReplyChannelHandle(message_.get(),
A<const BorrowedChannelHandle&>()))
- .WillOnce(Return(0));
- EXPECT_EQ(0, message_->Reply(handle));
+ .WillOnce(Return(Status<void>{}));
+ EXPECT_TRUE(message_->Reply(handle));
}
TEST_F(ServiceMessageTest, ReplyRemoteChannelHandle) {
RemoteChannelHandle handle{12345};
EXPECT_CALL(*endpoint(), MessageReplyChannelHandle(
message_.get(), A<const RemoteChannelHandle&>()))
- .WillOnce(Return(0));
- EXPECT_EQ(0, message_->Reply(handle));
+ .WillOnce(Return(Status<void>{}));
+ EXPECT_TRUE(message_->Reply(handle));
}
TEST_F(ServiceMessageTest, ReplyStatusInt) {
Status<int> status{123};
EXPECT_CALL(*endpoint(), MessageReply(message_.get(), status.get()))
- .WillOnce(Return(0));
- EXPECT_EQ(0, message_->Reply(status));
+ .WillOnce(Return(Status<void>{}));
+ EXPECT_TRUE(message_->Reply(status));
}
TEST_F(ServiceMessageTest, ReplyStatusError) {
Status<int> status{ErrorStatus{EIO}};
EXPECT_CALL(*endpoint(), MessageReply(message_.get(), -status.error()))
- .WillOnce(Return(0));
- EXPECT_EQ(0, message_->Reply(status));
+ .WillOnce(Return(Status<void>{}));
+ EXPECT_TRUE(message_->Reply(status));
}
TEST_F(ServiceMessageTest, Read) {
@@ -500,9 +507,9 @@
*endpoint(),
ReadMessageData(message_.get(), IoVecMatcher(kDataBuffer, kDataSize), 1))
.WillOnce(Return(50))
- .WillOnce(SetErrnoAndReturn(EACCES, -1));
- EXPECT_EQ(50, message_->Read(kDataBuffer, kDataSize));
- EXPECT_EQ(-EACCES, message_->Read(kDataBuffer, kDataSize));
+ .WillOnce(Return(ErrorStatus{EACCES}));
+ EXPECT_EQ(50u, message_->Read(kDataBuffer, kDataSize).get());
+ EXPECT_EQ(EACCES, message_->Read(kDataBuffer, kDataSize).error());
}
TEST_F(ServiceMessageTest, ReadVector) {
@@ -516,10 +523,10 @@
IoVecMatcher(IoVecArray{std::begin(vec), std::end(vec)}), 2))
.WillOnce(Return(30))
.WillOnce(Return(15))
- .WillOnce(SetErrnoAndReturn(EBADF, -1));
- EXPECT_EQ(30, message_->ReadVector(vec, 2));
- EXPECT_EQ(15, message_->ReadVector(vec));
- EXPECT_EQ(-EBADF, message_->ReadVector(vec));
+ .WillOnce(Return(ErrorStatus{EBADF}));
+ EXPECT_EQ(30u, message_->ReadVector(vec, 2).get());
+ EXPECT_EQ(15u, message_->ReadVector(vec).get());
+ EXPECT_EQ(EBADF, message_->ReadVector(vec).error());
}
TEST_F(ServiceMessageTest, Write) {
@@ -530,9 +537,9 @@
*endpoint(),
WriteMessageData(message_.get(), IoVecMatcher(kDataBuffer, kDataSize), 1))
.WillOnce(Return(50))
- .WillOnce(SetErrnoAndReturn(EBADMSG, -1));
- EXPECT_EQ(50, message_->Write(kDataBuffer, kDataSize));
- EXPECT_EQ(-EBADMSG, message_->Write(kDataBuffer, kDataSize));
+ .WillOnce(Return(ErrorStatus{EBADMSG}));
+ EXPECT_EQ(50u, message_->Write(kDataBuffer, kDataSize).get());
+ EXPECT_EQ(EBADMSG, message_->Write(kDataBuffer, kDataSize).error());
}
TEST_F(ServiceMessageTest, WriteVector) {
@@ -546,10 +553,10 @@
IoVecMatcher(IoVecArray{std::begin(vec), std::end(vec)}), 2))
.WillOnce(Return(30))
.WillOnce(Return(15))
- .WillOnce(SetErrnoAndReturn(EIO, -1));
- EXPECT_EQ(30, message_->WriteVector(vec, 2));
- EXPECT_EQ(15, message_->WriteVector(vec));
- EXPECT_EQ(-EIO, message_->WriteVector(vec, 2));
+ .WillOnce(Return(ErrorStatus{EIO}));
+ EXPECT_EQ(30u, message_->WriteVector(vec, 2).get());
+ EXPECT_EQ(15u, message_->WriteVector(vec).get());
+ EXPECT_EQ(EIO, message_->WriteVector(vec, 2).error());
}
TEST_F(ServiceMessageTest, PushLocalFileHandle) {
@@ -560,9 +567,9 @@
PushFileHandle(message_.get(), Matcher<const LocalHandle&>(
FileHandleMatcher(kFakeFd))))
.WillOnce(Return(12))
- .WillOnce(SetErrnoAndReturn(EIO, -1));
- EXPECT_EQ(12, message_->PushFileHandle(handle));
- EXPECT_EQ(-EIO, message_->PushFileHandle(handle));
+ .WillOnce(Return(ErrorStatus{EIO}));
+ EXPECT_EQ(12, message_->PushFileHandle(handle).get());
+ EXPECT_EQ(EIO, message_->PushFileHandle(handle).error());
handle.Release(); // Make sure we do not close the fake file descriptor.
}
@@ -574,9 +581,9 @@
PushFileHandle(message_.get(), Matcher<const BorrowedHandle&>(
FileHandleMatcher(kFakeFd))))
.WillOnce(Return(13))
- .WillOnce(SetErrnoAndReturn(EACCES, -1));
- EXPECT_EQ(13, message_->PushFileHandle(handle));
- EXPECT_EQ(-EACCES, message_->PushFileHandle(handle));
+ .WillOnce(Return(ErrorStatus{EACCES}));
+ EXPECT_EQ(13, message_->PushFileHandle(handle).get());
+ EXPECT_EQ(EACCES, message_->PushFileHandle(handle).error());
}
TEST_F(ServiceMessageTest, PushRemoteFileHandle) {
@@ -587,9 +594,9 @@
PushFileHandle(message_.get(), Matcher<const RemoteHandle&>(
FileHandleMatcher(kFakeFd))))
.WillOnce(Return(kFakeFd))
- .WillOnce(SetErrnoAndReturn(EIO, -1));
- EXPECT_EQ(kFakeFd, message_->PushFileHandle(handle));
- EXPECT_EQ(-EIO, message_->PushFileHandle(handle));
+ .WillOnce(Return(ErrorStatus{EIO}));
+ EXPECT_EQ(kFakeFd, message_->PushFileHandle(handle).get());
+ EXPECT_EQ(EIO, message_->PushFileHandle(handle).error());
}
TEST_F(ServiceMessageTest, PushLocalChannelHandle) {
@@ -600,9 +607,9 @@
Matcher<const LocalChannelHandle&>(
ChannelHandleMatcher(kValue))))
.WillOnce(Return(7))
- .WillOnce(SetErrnoAndReturn(EIO, -1));
- EXPECT_EQ(7, message_->PushChannelHandle(handle));
- EXPECT_EQ(-EIO, message_->PushChannelHandle(handle));
+ .WillOnce(Return(ErrorStatus{EIO}));
+ EXPECT_EQ(7, message_->PushChannelHandle(handle).get());
+ EXPECT_EQ(EIO, message_->PushChannelHandle(handle).error());
}
TEST_F(ServiceMessageTest, PushBorrowedChannelHandle) {
@@ -614,9 +621,9 @@
PushChannelHandle(message_.get(), Matcher<const BorrowedChannelHandle&>(
ChannelHandleMatcher(kValue))))
.WillOnce(Return(8))
- .WillOnce(SetErrnoAndReturn(EIO, -1));
- EXPECT_EQ(8, message_->PushChannelHandle(handle));
- EXPECT_EQ(-EIO, message_->PushChannelHandle(handle));
+ .WillOnce(Return(ErrorStatus{EIO}));
+ EXPECT_EQ(8, message_->PushChannelHandle(handle).get());
+ EXPECT_EQ(EIO, message_->PushChannelHandle(handle).error());
}
TEST_F(ServiceMessageTest, PushRemoteChannelHandle) {
@@ -628,9 +635,9 @@
PushChannelHandle(message_.get(), Matcher<const RemoteChannelHandle&>(
ChannelHandleMatcher(kValue))))
.WillOnce(Return(kValue))
- .WillOnce(SetErrnoAndReturn(EIO, -1));
- EXPECT_EQ(kValue, message_->PushChannelHandle(handle));
- EXPECT_EQ(-EIO, message_->PushChannelHandle(handle));
+ .WillOnce(Return(ErrorStatus{EIO}));
+ EXPECT_EQ(kValue, message_->PushChannelHandle(handle).get());
+ EXPECT_EQ(EIO, message_->PushChannelHandle(handle).error());
}
TEST_F(ServiceMessageTest, GetFileHandle) {
@@ -701,8 +708,8 @@
int kClearMask = 1;
int kSetMask = 2;
EXPECT_CALL(*endpoint(), ModifyChannelEvents(kTestCid, kClearMask, kSetMask))
- .WillOnce(Return(0));
- EXPECT_EQ(0, message_->ModifyChannelEvents(kClearMask, kSetMask));
+ .WillOnce(Return(Status<void>{}));
+ EXPECT_TRUE(message_->ModifyChannelEvents(kClearMask, kSetMask));
}
TEST_F(ServiceMessageTest, PushChannelSameService) {
@@ -733,7 +740,9 @@
TEST_F(ServiceMessageTest, PushChannelDifferentService) {
ExpectDefaultHandleMessage();
auto endpoint2 = std::make_unique<testing::StrictMock<MockEndpoint>>();
- EXPECT_CALL(*endpoint2, SetService(_)).Times(2).WillRepeatedly(Return(0));
+ EXPECT_CALL(*endpoint2, SetService(_))
+ .Times(2)
+ .WillRepeatedly(Return(Status<void>{}));
auto service2 =
std::make_shared<MockService>("MockSvc2", std::move(endpoint2));
@@ -779,7 +788,9 @@
TEST_F(ServiceMessageTest, CheckChannelDifferentService) {
ExpectDefaultHandleMessage();
auto endpoint2 = std::make_unique<testing::StrictMock<MockEndpoint>>();
- EXPECT_CALL(*endpoint2, SetService(_)).Times(2).WillRepeatedly(Return(0));
+ EXPECT_CALL(*endpoint2, SetService(_))
+ .Times(2)
+ .WillRepeatedly(Return(Status<void>{}));
auto service2 =
std::make_shared<MockService>("MockSvc2", std::move(endpoint2));
diff --git a/libs/vr/libpdx_default_transport/pdx_benchmarks.cpp b/libs/vr/libpdx_default_transport/pdx_benchmarks.cpp
index de02401..0b658fb 100644
--- a/libs/vr/libpdx_default_transport/pdx_benchmarks.cpp
+++ b/libs/vr/libpdx_default_transport/pdx_benchmarks.cpp
@@ -38,6 +38,7 @@
using android::pdx::Channel;
using android::pdx::ClientBase;
using android::pdx::Endpoint;
+using android::pdx::ErrorStatus;
using android::pdx::Message;
using android::pdx::Service;
using android::pdx::ServiceBase;
@@ -246,7 +247,7 @@
<< message.GetChannelId();
}
- int HandleMessage(Message& message) override {
+ Status<void> HandleMessage(Message& message) override {
ATRACE_NAME("BenchmarkService::HandleMessage");
switch (message.GetOp()) {
@@ -254,30 +255,27 @@
VLOG(1) << "BenchmarkService::HandleMessage: op=nop";
{
ATRACE_NAME("Reply");
- CHECK(message.Reply(0) == 0);
+ CHECK(message.Reply(0));
}
- return 0;
+ return {};
case BenchmarkOps::Write: {
VLOG(1) << "BenchmarkService::HandleMessage: op=write send_length="
<< message.GetSendLength()
<< " receive_length=" << message.GetReceiveLength();
- const ssize_t expected_length =
- static_cast<ssize_t>(message.GetSendLength());
- const ssize_t actual_length =
- expected_length > 0
- ? message.Read(send_buffer.data(), message.GetSendLength())
- : 0;
+ Status<void> status;
+ if (message.GetSendLength())
+ status = message.ReadAll(send_buffer.data(), message.GetSendLength());
{
ATRACE_NAME("Reply");
- if (actual_length < expected_length)
- CHECK(message.ReplyError(EIO) == 0);
+ if (!status)
+ CHECK(message.ReplyError(status.error()));
else
- CHECK(message.Reply(actual_length) == 0);
+ CHECK(message.Reply(message.GetSendLength()));
}
- return 0;
+ return {};
}
case BenchmarkOps::Read: {
@@ -285,22 +283,20 @@
<< message.GetSendLength()
<< " receive_length=" << message.GetReceiveLength();
- const ssize_t expected_length =
- static_cast<ssize_t>(message.GetReceiveLength());
- const ssize_t actual_length =
- expected_length > 0
- ? message.Write(receive_buffer.data(),
- message.GetReceiveLength())
- : 0;
+ Status<void> status;
+ if (message.GetReceiveLength()) {
+ status = message.WriteAll(receive_buffer.data(),
+ message.GetReceiveLength());
+ }
{
ATRACE_NAME("Reply");
- if (actual_length < expected_length)
- CHECK(message.ReplyError(EIO) == 0);
+ if (!status)
+ CHECK(message.ReplyError(status.error()));
else
- CHECK(message.Reply(actual_length) == 0);
+ CHECK(message.Reply(message.GetReceiveLength()));
}
- return 0;
+ return {};
}
case BenchmarkOps::Echo: {
@@ -308,31 +304,28 @@
<< message.GetSendLength()
<< " receive_length=" << message.GetReceiveLength();
- const ssize_t expected_length =
- static_cast<ssize_t>(message.GetSendLength());
- ssize_t actual_length =
- expected_length > 0
- ? message.Read(send_buffer.data(), message.GetSendLength())
- : 0;
+ Status<void> status;
+ if (message.GetSendLength())
+ status = message.ReadAll(send_buffer.data(), message.GetSendLength());
- if (actual_length < expected_length) {
- CHECK(message.ReplyError(EIO) == 0);
- return 0;
+ if (!status) {
+ CHECK(message.ReplyError(status.error()));
+ return {};
}
- actual_length =
- expected_length > 0
- ? message.Write(send_buffer.data(), message.GetSendLength())
- : 0;
+ if (message.GetSendLength()) {
+ status =
+ message.WriteAll(send_buffer.data(), message.GetSendLength());
+ }
{
ATRACE_NAME("Reply");
- if (actual_length < expected_length)
- CHECK(message.ReplyError(EIO) == 0);
+ if (!status)
+ CHECK(message.ReplyError(status.error()));
else
- CHECK(message.Reply(actual_length) == 0);
+ CHECK(message.Reply(message.GetSendLength()));
}
- return 0;
+ return {};
}
case BenchmarkOps::Stats: {
@@ -348,7 +341,7 @@
RemoteMethodReturn<BenchmarkRPC::Stats>(
message, BenchmarkRPC::Stats::Return{receive_time_ns, GetClockNs(),
sched_stats_});
- return 0;
+ return {};
}
case BenchmarkOps::WriteVector:
@@ -358,7 +351,7 @@
DispatchRemoteMethod<BenchmarkRPC::WriteVector>(
*this, &BenchmarkService::OnWriteVector, message, kMaxMessageSize);
- return 0;
+ return {};
case BenchmarkOps::EchoVector:
VLOG(1) << "BenchmarkService::HandleMessage: op=echovec send_length="
@@ -367,11 +360,11 @@
DispatchRemoteMethod<BenchmarkRPC::EchoVector>(
*this, &BenchmarkService::OnEchoVector, message, kMaxMessageSize);
- return 0;
+ return {};
case BenchmarkOps::Quit:
Cancel();
- return -ESHUTDOWN;
+ return ErrorStatus{ESHUTDOWN};
default:
VLOG(1) << "BenchmarkService::HandleMessage: default case; op="
@@ -543,17 +536,17 @@
const std::shared_ptr<BenchmarkService>& local_service) {
SetThreadName("service" + std::to_string(service_id));
- // Read the inital schedstats for this thread from procfs.
+ // Read the initial schedstats for this thread from procfs.
local_service->UpdateSchedStats();
ATRACE_NAME("BenchmarkService::Dispatch");
while (!done) {
- const int ret = local_service->ReceiveAndDispatch();
- if (ret < 0) {
- if (ret != -ESHUTDOWN) {
+ auto ret = local_service->ReceiveAndDispatch();
+ if (!ret) {
+ if (ret.error() != ESHUTDOWN) {
std::cerr << "Error while dispatching message on thread "
<< thread_id << " service " << service_id << ": "
- << strerror(-ret) << std::endl;
+ << ret.GetErrorMessage() << std::endl;
} else {
std::cerr << "Quitting thread " << thread_id << " service "
<< service_id << std::endl;
diff --git a/libs/vr/libpdx_uds/Android.bp b/libs/vr/libpdx_uds/Android.bp
index 09eeaa0..9f308ec 100644
--- a/libs/vr/libpdx_uds/Android.bp
+++ b/libs/vr/libpdx_uds/Android.bp
@@ -41,6 +41,8 @@
"libpdx",
],
shared_libs: [
+ "libbase",
+ "libcutils",
"liblog",
"libutils",
],
diff --git a/libs/vr/libpdx_uds/ipc_helper.cpp b/libs/vr/libpdx_uds/ipc_helper.cpp
index ee7299e..fe5c986 100644
--- a/libs/vr/libpdx_uds/ipc_helper.cpp
+++ b/libs/vr/libpdx_uds/ipc_helper.cpp
@@ -87,7 +87,7 @@
OutputResourceMapper* SendPayload::GetOutputResourceMapper() { return this; }
// OutputResourceMapper
-FileReference SendPayload::PushFileHandle(const LocalHandle& handle) {
+Status<FileReference> SendPayload::PushFileHandle(const LocalHandle& handle) {
if (handle) {
const int ref = file_handles_.size();
file_handles_.push_back(handle.Get());
@@ -97,7 +97,8 @@
}
}
-FileReference SendPayload::PushFileHandle(const BorrowedHandle& handle) {
+Status<FileReference> SendPayload::PushFileHandle(
+ const BorrowedHandle& handle) {
if (handle) {
const int ref = file_handles_.size();
file_handles_.push_back(handle.Get());
@@ -107,21 +108,21 @@
}
}
-FileReference SendPayload::PushFileHandle(const RemoteHandle& handle) {
+Status<FileReference> SendPayload::PushFileHandle(const RemoteHandle& handle) {
return handle.Get();
}
-ChannelReference SendPayload::PushChannelHandle(
+Status<ChannelReference> SendPayload::PushChannelHandle(
const LocalChannelHandle& /*handle*/) {
- return -1;
+ return ErrorStatus{EOPNOTSUPP};
}
-ChannelReference SendPayload::PushChannelHandle(
+Status<ChannelReference> SendPayload::PushChannelHandle(
const BorrowedChannelHandle& /*handle*/) {
- return -1;
+ return ErrorStatus{EOPNOTSUPP};
}
-ChannelReference SendPayload::PushChannelHandle(
+Status<ChannelReference> SendPayload::PushChannelHandle(
const RemoteChannelHandle& /*handle*/) {
- return -1;
+ return ErrorStatus{EOPNOTSUPP};
}
Status<void> ReceivePayload::Receive(int socket_fd) {
diff --git a/libs/vr/libpdx_uds/private/uds/ipc_helper.h b/libs/vr/libpdx_uds/private/uds/ipc_helper.h
index 00f3490..80530bf 100644
--- a/libs/vr/libpdx_uds/private/uds/ipc_helper.h
+++ b/libs/vr/libpdx_uds/private/uds/ipc_helper.h
@@ -33,13 +33,14 @@
OutputResourceMapper* GetOutputResourceMapper() override;
// OutputResourceMapper
- FileReference PushFileHandle(const LocalHandle& handle) override;
- FileReference PushFileHandle(const BorrowedHandle& handle) override;
- FileReference PushFileHandle(const RemoteHandle& handle) override;
- ChannelReference PushChannelHandle(const LocalChannelHandle& handle) override;
- ChannelReference PushChannelHandle(
+ Status<FileReference> PushFileHandle(const LocalHandle& handle) override;
+ Status<FileReference> PushFileHandle(const BorrowedHandle& handle) override;
+ Status<FileReference> PushFileHandle(const RemoteHandle& handle) override;
+ Status<ChannelReference> PushChannelHandle(
+ const LocalChannelHandle& handle) override;
+ Status<ChannelReference> PushChannelHandle(
const BorrowedChannelHandle& handle) override;
- ChannelReference PushChannelHandle(
+ Status<ChannelReference> PushChannelHandle(
const RemoteChannelHandle& handle) override;
private:
diff --git a/libs/vr/libpdx_uds/private/uds/service_endpoint.h b/libs/vr/libpdx_uds/private/uds/service_endpoint.h
index 3ec8519..9d038cb 100644
--- a/libs/vr/libpdx_uds/private/uds/service_endpoint.h
+++ b/libs/vr/libpdx_uds/private/uds/service_endpoint.h
@@ -39,41 +39,40 @@
~Endpoint() override = default;
uint32_t GetIpcTag() const override { return kIpcTag; }
- int SetService(Service* service) override;
- int SetChannel(int channel_id, Channel* channel) override;
- int CloseChannel(int channel_id) override;
- int ModifyChannelEvents(int channel_id, int clear_mask,
- int set_mask) override;
+ Status<void> SetService(Service* service) override;
+ Status<void> SetChannel(int channel_id, Channel* channel) override;
+ Status<void> CloseChannel(int channel_id) override;
+ Status<void> ModifyChannelEvents(int channel_id, int clear_mask,
+ int set_mask) override;
Status<RemoteChannelHandle> PushChannel(Message* message, int flags,
Channel* channel,
int* channel_id) override;
Status<int> CheckChannel(const Message* message, ChannelReference ref,
Channel** channel) override;
- int DefaultHandleMessage(const MessageInfo& info) override;
- int MessageReceive(Message* message) override;
- int MessageReply(Message* message, int return_code) override;
- int MessageReplyFd(Message* message, unsigned int push_fd) override;
- int MessageReplyChannelHandle(Message* message,
- const LocalChannelHandle& handle) override;
- int MessageReplyChannelHandle(Message* message,
- const BorrowedChannelHandle& handle) override;
- int MessageReplyChannelHandle(Message* message,
- const RemoteChannelHandle& handle) override;
- ssize_t ReadMessageData(Message* message, const iovec* vector,
- size_t vector_length) override;
- ssize_t WriteMessageData(Message* message, const iovec* vector,
- size_t vector_length) override;
- FileReference PushFileHandle(Message* message,
- const LocalHandle& handle) override;
- FileReference PushFileHandle(Message* message,
- const BorrowedHandle& handle) override;
- FileReference PushFileHandle(Message* message,
- const RemoteHandle& handle) override;
- ChannelReference PushChannelHandle(Message* message,
- const LocalChannelHandle& handle) override;
- ChannelReference PushChannelHandle(
+ Status<void> MessageReceive(Message* message) override;
+ Status<void> MessageReply(Message* message, int return_code) override;
+ Status<void> MessageReplyFd(Message* message, unsigned int push_fd) override;
+ Status<void> MessageReplyChannelHandle(
+ Message* message, const LocalChannelHandle& handle) override;
+ Status<void> MessageReplyChannelHandle(
Message* message, const BorrowedChannelHandle& handle) override;
- ChannelReference PushChannelHandle(
+ Status<void> MessageReplyChannelHandle(
+ Message* message, const RemoteChannelHandle& handle) override;
+ Status<size_t> ReadMessageData(Message* message, const iovec* vector,
+ size_t vector_length) override;
+ Status<size_t> WriteMessageData(Message* message, const iovec* vector,
+ size_t vector_length) override;
+ Status<FileReference> PushFileHandle(Message* message,
+ const LocalHandle& handle) override;
+ Status<FileReference> PushFileHandle(Message* message,
+ const BorrowedHandle& handle) override;
+ Status<FileReference> PushFileHandle(Message* message,
+ const RemoteHandle& handle) override;
+ Status<ChannelReference> PushChannelHandle(
+ Message* message, const LocalChannelHandle& handle) override;
+ Status<ChannelReference> PushChannelHandle(
+ Message* message, const BorrowedChannelHandle& handle) override;
+ Status<ChannelReference> PushChannelHandle(
Message* message, const RemoteChannelHandle& handle) override;
LocalHandle GetFileHandle(Message* message, FileReference ref) const override;
LocalChannelHandle GetChannelHandle(Message* message,
@@ -82,15 +81,22 @@
void* AllocateMessageState() override;
void FreeMessageState(void* state) override;
- int Cancel() override;
+ Status<void> Cancel() override;
// Open an endpoint at the given path.
// Second parameter is unused for UDS, but we have it here for compatibility
// in signature with servicefs::Endpoint::Create().
+ // This method uses |endpoint_path| as a relative path to endpoint socket
+ // created by init process.
static std::unique_ptr<Endpoint> Create(const std::string& endpoint_path,
mode_t /*unused_mode*/ = kDefaultMode,
bool blocking = kDefaultBlocking);
+ // Helper method to create an endpoint at the given UDS socket path. This
+ // method physically creates and binds a socket at that path.
+ static std::unique_ptr<Endpoint> CreateAndBindSocket(
+ const std::string& endpoint_path, bool blocking = kDefaultBlocking);
+
int epoll_fd() const { return epoll_fd_.Get(); }
private:
@@ -117,7 +123,7 @@
Status<void> OnNewChannel(LocalHandle channel_fd);
Status<ChannelData*> OnNewChannelLocked(LocalHandle channel_fd,
Channel* channel_state);
- int CloseChannelLocked(int channel_id);
+ Status<void> CloseChannelLocked(int channel_id);
Status<void> ReenableEpollEvent(int fd);
Channel* GetChannelState(int channel_id);
int GetChannelSocketFd(int channel_id);
diff --git a/libs/vr/libpdx_uds/remote_method_tests.cpp b/libs/vr/libpdx_uds/remote_method_tests.cpp
index 9050500..3109753 100644
--- a/libs/vr/libpdx_uds/remote_method_tests.cpp
+++ b/libs/vr/libpdx_uds/remote_method_tests.cpp
@@ -342,87 +342,87 @@
// Test service that encodes/decodes messages from clients.
class TestService : public ServiceBase<TestService> {
public:
- int HandleMessage(Message& message) override {
+ Status<void> HandleMessage(Message& message) override {
switch (message.GetOp()) {
case TestInterface::Add::Opcode:
DispatchRemoteMethod<TestInterface::Add>(*this, &TestService::OnAdd,
message);
- return 0;
+ return {};
case TestInterface::Foo::Opcode:
DispatchRemoteMethod<TestInterface::Foo>(*this, &TestService::OnFoo,
message);
- return 0;
+ return {};
case TestInterface::Concatenate::Opcode:
DispatchRemoteMethod<TestInterface::Concatenate>(
*this, &TestService::OnConcatenate, message);
- return 0;
+ return {};
case TestInterface::SumVector::Opcode:
DispatchRemoteMethod<TestInterface::SumVector>(
*this, &TestService::OnSumVector, message);
- return 0;
+ return {};
case TestInterface::StringLength::Opcode:
DispatchRemoteMethod<TestInterface::StringLength>(
*this, &TestService::OnStringLength, message);
- return 0;
+ return {};
case TestInterface::SendTestType::Opcode:
DispatchRemoteMethod<TestInterface::SendTestType>(
*this, &TestService::OnSendTestType, message);
- return 0;
+ return {};
case TestInterface::SendVector::Opcode:
DispatchRemoteMethod<TestInterface::SendVector>(
*this, &TestService::OnSendVector, message);
- return 0;
+ return {};
case TestInterface::Rot13::Opcode:
DispatchRemoteMethod<TestInterface::Rot13>(*this, &TestService::OnRot13,
message);
- return 0;
+ return {};
case TestInterface::NoArgs::Opcode:
DispatchRemoteMethod<TestInterface::NoArgs>(
*this, &TestService::OnNoArgs, message);
- return 0;
+ return {};
case TestInterface::SendFile::Opcode:
DispatchRemoteMethod<TestInterface::SendFile>(
*this, &TestService::OnSendFile, message);
- return 0;
+ return {};
case TestInterface::GetFile::Opcode:
DispatchRemoteMethod<TestInterface::GetFile>(
*this, &TestService::OnGetFile, message);
- return 0;
+ return {};
case TestInterface::GetTestFdType::Opcode:
DispatchRemoteMethod<TestInterface::GetTestFdType>(
*this, &TestService::OnGetTestFdType, message);
- return 0;
+ return {};
case TestInterface::OpenFiles::Opcode:
DispatchRemoteMethod<TestInterface::OpenFiles>(
*this, &TestService::OnOpenFiles, message);
- return 0;
+ return {};
case TestInterface::ReadFile::Opcode:
DispatchRemoteMethod<TestInterface::ReadFile>(
*this, &TestService::OnReadFile, message);
- return 0;
+ return {};
case TestInterface::PushChannel::Opcode:
DispatchRemoteMethod<TestInterface::PushChannel>(
*this, &TestService::OnPushChannel, message);
- return 0;
+ return {};
case TestInterface::Positive::Opcode:
DispatchRemoteMethod<TestInterface::Positive>(
*this, &TestService::OnPositive, message);
- return 0;
+ return {};
default:
return Service::DefaultHandleMessage(message);
@@ -433,7 +433,8 @@
friend BASE;
TestService()
- : BASE("TestService", Endpoint::Create(TestInterface::kClientPath)) {}
+ : BASE("TestService",
+ Endpoint::CreateAndBindSocket(TestInterface::kClientPath)) {}
int OnAdd(Message&, int a, int b) { return a + b; }
diff --git a/libs/vr/libpdx_uds/service_endpoint.cpp b/libs/vr/libpdx_uds/service_endpoint.cpp
index 7bf753d..f89b8a8 100644
--- a/libs/vr/libpdx_uds/service_endpoint.cpp
+++ b/libs/vr/libpdx_uds/service_endpoint.cpp
@@ -19,6 +19,7 @@
using android::pdx::BorrowedChannelHandle;
using android::pdx::BorrowedHandle;
using android::pdx::ChannelReference;
+using android::pdx::ErrorStatus;
using android::pdx::FileReference;
using android::pdx::LocalChannelHandle;
using android::pdx::LocalHandle;
@@ -51,14 +52,14 @@
return true;
}
- FileReference PushFileHandle(BorrowedHandle handle) {
+ Status<FileReference> PushFileHandle(BorrowedHandle handle) {
if (!handle)
return handle.Get();
response.file_descriptors.push_back(std::move(handle));
return response.file_descriptors.size() - 1;
}
- ChannelReference PushChannelHandle(BorrowedChannelHandle handle) {
+ Status<ChannelReference> PushChannelHandle(BorrowedChannelHandle handle) {
if (!handle)
return handle.value();
@@ -70,14 +71,14 @@
response.channels.push_back(std::move(channel_info));
return response.channels.size() - 1;
} else {
- return -1;
+ return ErrorStatus{EINVAL};
}
}
- ChannelReference PushChannelHandle(BorrowedHandle data_fd,
- BorrowedHandle event_fd) {
+ Status<ChannelReference> PushChannelHandle(BorrowedHandle data_fd,
+ BorrowedHandle event_fd) {
if (!data_fd || !event_fd)
- return -1;
+ return ErrorStatus{EINVAL};
ChannelInfo<BorrowedHandle> channel_info;
channel_info.data_fd = std::move(data_fd);
channel_info.event_fd = std::move(event_fd);
@@ -85,8 +86,8 @@
return response.channels.size() - 1;
}
- ssize_t WriteData(const iovec* vector, size_t vector_length) {
- ssize_t size = 0;
+ Status<size_t> WriteData(const iovec* vector, size_t vector_length) {
+ size_t size = 0;
for (size_t i = 0; i < vector_length; i++) {
const auto* data = reinterpret_cast<const uint8_t*>(vector[i].iov_base);
response_data.insert(response_data.end(), data, data + vector[i].iov_len);
@@ -95,9 +96,9 @@
return size;
}
- ssize_t ReadData(const iovec* vector, size_t vector_length) {
+ Status<size_t> ReadData(const iovec* vector, size_t vector_length) {
size_t size_remaining = request_data.size() - request_data_read_pos;
- ssize_t size = 0;
+ size_t size = 0;
for (size_t i = 0; i < vector_length && size_remaining > 0; i++) {
size_t size_to_copy = std::min(size_remaining, vector[i].iov_len);
memcpy(vector[i].iov_base, request_data.data() + request_data_read_pos,
@@ -214,18 +215,18 @@
return status;
}
-int Endpoint::SetService(Service* service) {
+Status<void> Endpoint::SetService(Service* service) {
service_ = service;
- return 0;
+ return {};
}
-int Endpoint::SetChannel(int channel_id, Channel* channel) {
+Status<void> Endpoint::SetChannel(int channel_id, Channel* channel) {
std::lock_guard<std::mutex> autolock(channel_mutex_);
auto channel_data = channels_.find(channel_id);
if (channel_data == channels_.end())
- return -EINVAL;
+ return ErrorStatus{EINVAL};
channel_data->second.channel_state = channel;
- return 0;
+ return {};
}
Status<void> Endpoint::OnNewChannel(LocalHandle channel_fd) {
@@ -269,44 +270,46 @@
return {};
}
-int Endpoint::CloseChannel(int channel_id) {
+Status<void> Endpoint::CloseChannel(int channel_id) {
std::lock_guard<std::mutex> autolock(channel_mutex_);
return CloseChannelLocked(channel_id);
}
-int Endpoint::CloseChannelLocked(int channel_id) {
+Status<void> Endpoint::CloseChannelLocked(int channel_id) {
ALOGD_IF(TRACE, "Endpoint::CloseChannelLocked: channel_id=%d", channel_id);
auto channel_data = channels_.find(channel_id);
if (channel_data == channels_.end())
- return -EINVAL;
+ return ErrorStatus{EINVAL};
- int ret = 0;
+ Status<void> status;
epoll_event dummy; // See BUGS in man 2 epoll_ctl.
if (epoll_ctl(epoll_fd_.Get(), EPOLL_CTL_DEL, channel_id, &dummy) < 0) {
- ret = -errno;
+ status.SetError(errno);
ALOGE(
"Endpoint::CloseChannelLocked: Failed to remove channel from endpoint: "
"%s\n",
strerror(errno));
+ } else {
+ status.SetValue();
}
channels_.erase(channel_data);
- return ret;
+ return status;
}
-int Endpoint::ModifyChannelEvents(int channel_id, int clear_mask,
- int set_mask) {
+Status<void> Endpoint::ModifyChannelEvents(int channel_id, int clear_mask,
+ int set_mask) {
std::lock_guard<std::mutex> autolock(channel_mutex_);
auto search = channels_.find(channel_id);
if (search != channels_.end()) {
auto& channel_data = search->second;
channel_data.event_set.ModifyEvents(clear_mask, set_mask);
- return 0;
+ return {};
}
- return -EINVAL;
+ return ErrorStatus{EINVAL};
}
Status<RemoteChannelHandle> Endpoint::PushChannel(Message* message,
@@ -337,17 +340,19 @@
*channel_id = local_socket.Get();
auto channel_data = OnNewChannelLocked(std::move(local_socket), channel);
if (!channel_data)
- return ErrorStatus(channel_data.error());
+ return channel_data.error_status();
// Flags are ignored for now.
// TODO(xiaohuit): Implement those.
auto* state = static_cast<MessageState*>(message->GetState());
- ChannelReference ref = state->PushChannelHandle(
+ Status<ChannelReference> ref = state->PushChannelHandle(
remote_socket.Borrow(),
channel_data.get()->event_set.event_fd().Borrow());
+ if (!ref)
+ return ref.error_status();
state->sockets_to_close.push_back(std::move(remote_socket));
- return RemoteChannelHandle{ref};
+ return RemoteChannelHandle{ref.get()};
}
Status<int> Endpoint::CheckChannel(const Message* /*message*/,
@@ -357,13 +362,6 @@
return ErrorStatus(EFAULT);
}
-int Endpoint::DefaultHandleMessage(const MessageInfo& /* info */) {
- ALOGE(
- "Endpoint::CheckChannel: Not implemented! Endpoint DefaultHandleMessage "
- "does nothing!");
- return 0;
-}
-
Channel* Endpoint::GetChannelState(int channel_id) {
std::lock_guard<std::mutex> autolock(channel_mutex_);
auto channel_data = channels_.find(channel_id);
@@ -464,7 +462,7 @@
*message = Message{info};
}
-int Endpoint::MessageReceive(Message* message) {
+Status<void> Endpoint::MessageReceive(Message* message) {
// Receive at most one event from the epoll set. This should prevent multiple
// dispatch threads from attempting to handle messages on the same socket at
// the same time.
@@ -474,40 +472,36 @@
if (count < 0) {
ALOGE("Endpoint::MessageReceive: Failed to wait for epoll events: %s\n",
strerror(errno));
- return -errno;
+ return ErrorStatus{errno};
} else if (count == 0) {
- return -ETIMEDOUT;
+ return ErrorStatus{ETIMEDOUT};
}
if (event.data.fd == cancel_event_fd_.Get()) {
- return -ESHUTDOWN;
+ return ErrorStatus{ESHUTDOWN};
}
if (event.data.fd == socket_fd_.Get()) {
auto status = AcceptConnection(message);
if (!status)
- return -status.error();
- status = ReenableEpollEvent(socket_fd_.Get());
- return status ? 0 : -status.error();
+ return status;
+ return ReenableEpollEvent(socket_fd_.Get());
}
int channel_id = event.data.fd;
if (event.events & (EPOLLRDHUP | EPOLLHUP)) {
BuildCloseMessage(channel_id, message);
- return 0;
+ return {};
}
- auto status = ReceiveMessageForChannel(channel_id, message);
- if (!status)
- return -status.error();
- return 0;
+ return ReceiveMessageForChannel(channel_id, message);
}
-int Endpoint::MessageReply(Message* message, int return_code) {
+Status<void> Endpoint::MessageReply(Message* message, int return_code) {
const int channel_id = message->GetChannelId();
const int channel_socket = GetChannelSocketFd(channel_id);
if (channel_socket < 0)
- return -EBADF;
+ return ErrorStatus{EBADF};
auto* state = static_cast<MessageState*>(message->GetState());
switch (message->GetOp()) {
@@ -515,12 +509,17 @@
return CloseChannel(channel_id);
case opcodes::CHANNEL_OPEN:
- if (return_code < 0)
+ if (return_code < 0) {
return CloseChannel(channel_id);
- // Reply with the event fd.
- return_code = state->PushFileHandle(
- BorrowedHandle{GetChannelEventFd(channel_socket)});
- state->response_data.clear(); // Just in case...
+ } else {
+ // Reply with the event fd.
+ auto push_status = state->PushFileHandle(
+ BorrowedHandle{GetChannelEventFd(channel_socket)});
+ state->response_data.clear(); // Just in case...
+ if (!push_status)
+ return push_status.error_status();
+ return_code = push_status.get();
+ }
break;
}
@@ -535,76 +534,82 @@
if (status)
status = ReenableEpollEvent(channel_socket);
- return status ? 0 : -status.error();
+ return status;
}
-int Endpoint::MessageReplyFd(Message* message, unsigned int push_fd) {
+Status<void> Endpoint::MessageReplyFd(Message* message, unsigned int push_fd) {
auto* state = static_cast<MessageState*>(message->GetState());
auto ref = state->PushFileHandle(BorrowedHandle{static_cast<int>(push_fd)});
- return MessageReply(message, ref);
+ if (!ref)
+ return ref.error_status();
+ return MessageReply(message, ref.get());
}
-int Endpoint::MessageReplyChannelHandle(Message* message,
- const LocalChannelHandle& handle) {
+Status<void> Endpoint::MessageReplyChannelHandle(
+ Message* message, const LocalChannelHandle& handle) {
auto* state = static_cast<MessageState*>(message->GetState());
auto ref = state->PushChannelHandle(handle.Borrow());
- return MessageReply(message, ref);
+ if (!ref)
+ return ref.error_status();
+ return MessageReply(message, ref.get());
}
-int Endpoint::MessageReplyChannelHandle(Message* message,
- const BorrowedChannelHandle& handle) {
+Status<void> Endpoint::MessageReplyChannelHandle(
+ Message* message, const BorrowedChannelHandle& handle) {
auto* state = static_cast<MessageState*>(message->GetState());
auto ref = state->PushChannelHandle(handle.Duplicate());
- return MessageReply(message, ref);
+ if (!ref)
+ return ref.error_status();
+ return MessageReply(message, ref.get());
}
-int Endpoint::MessageReplyChannelHandle(Message* message,
- const RemoteChannelHandle& handle) {
+Status<void> Endpoint::MessageReplyChannelHandle(
+ Message* message, const RemoteChannelHandle& handle) {
return MessageReply(message, handle.value());
}
-ssize_t Endpoint::ReadMessageData(Message* message, const iovec* vector,
- size_t vector_length) {
+Status<size_t> Endpoint::ReadMessageData(Message* message, const iovec* vector,
+ size_t vector_length) {
auto* state = static_cast<MessageState*>(message->GetState());
return state->ReadData(vector, vector_length);
}
-ssize_t Endpoint::WriteMessageData(Message* message, const iovec* vector,
- size_t vector_length) {
+Status<size_t> Endpoint::WriteMessageData(Message* message, const iovec* vector,
+ size_t vector_length) {
auto* state = static_cast<MessageState*>(message->GetState());
return state->WriteData(vector, vector_length);
}
-FileReference Endpoint::PushFileHandle(Message* message,
- const LocalHandle& handle) {
+Status<FileReference> Endpoint::PushFileHandle(Message* message,
+ const LocalHandle& handle) {
auto* state = static_cast<MessageState*>(message->GetState());
return state->PushFileHandle(handle.Borrow());
}
-FileReference Endpoint::PushFileHandle(Message* message,
- const BorrowedHandle& handle) {
+Status<FileReference> Endpoint::PushFileHandle(Message* message,
+ const BorrowedHandle& handle) {
auto* state = static_cast<MessageState*>(message->GetState());
return state->PushFileHandle(handle.Duplicate());
}
-FileReference Endpoint::PushFileHandle(Message* /*message*/,
- const RemoteHandle& handle) {
+Status<FileReference> Endpoint::PushFileHandle(Message* /*message*/,
+ const RemoteHandle& handle) {
return handle.Get();
}
-ChannelReference Endpoint::PushChannelHandle(Message* message,
- const LocalChannelHandle& handle) {
+Status<ChannelReference> Endpoint::PushChannelHandle(
+ Message* message, const LocalChannelHandle& handle) {
auto* state = static_cast<MessageState*>(message->GetState());
return state->PushChannelHandle(handle.Borrow());
}
-ChannelReference Endpoint::PushChannelHandle(
+Status<ChannelReference> Endpoint::PushChannelHandle(
Message* message, const BorrowedChannelHandle& handle) {
auto* state = static_cast<MessageState*>(message->GetState());
return state->PushChannelHandle(handle.Duplicate());
}
-ChannelReference Endpoint::PushChannelHandle(
+Status<ChannelReference> Endpoint::PushChannelHandle(
Message* /*message*/, const RemoteChannelHandle& handle) {
return handle.value();
}
@@ -624,8 +629,10 @@
return handle;
}
-int Endpoint::Cancel() {
- return (eventfd_write(cancel_event_fd_.Get(), 1) < 0) ? -errno : 0;
+Status<void> Endpoint::Cancel() {
+ if (eventfd_write(cancel_event_fd_.Get(), 1) < 0)
+ return ErrorStatus{errno};
+ return {};
}
std::unique_ptr<Endpoint> Endpoint::Create(const std::string& endpoint_path,
@@ -634,6 +641,14 @@
return std::unique_ptr<Endpoint>(new Endpoint(endpoint_path, blocking));
}
+std::unique_ptr<Endpoint> Endpoint::CreateAndBindSocket(
+ const std::string& endpoint_path, bool blocking) {
+ // TODO(avakulenko): When Endpoint can differentiate between absolute paths
+ // and relative paths/socket names created by the init process, change this
+ // code to reflect the fact that we want to use absolute paths here.
+ return std::unique_ptr<Endpoint>(new Endpoint(endpoint_path, blocking));
+}
+
} // namespace uds
} // namespace pdx
} // namespace android
diff --git a/libs/vr/libpdx_uds/service_framework_tests.cpp b/libs/vr/libpdx_uds/service_framework_tests.cpp
index 9e31e82..2943239 100644
--- a/libs/vr/libpdx_uds/service_framework_tests.cpp
+++ b/libs/vr/libpdx_uds/service_framework_tests.cpp
@@ -119,106 +119,106 @@
}
}
- int HandleMessage(Message& message) override {
+ Status<void> HandleMessage(Message& message) override {
switch (message.GetOp()) {
case TEST_OP_GET_SERVICE_ID:
- REPLY_MESSAGE_RETURN(message, service_id_, 0);
+ REPLY_MESSAGE_RETURN(message, service_id_, {});
// Set the test channel to the TestChannel for the current channel. Other
// messages can use this to perform tests.
case TEST_OP_SET_TEST_CHANNEL:
test_channel_ = message.GetChannel<TestChannel>();
- REPLY_MESSAGE_RETURN(message, 0, 0);
+ REPLY_MESSAGE_RETURN(message, 0, {});
// Return the channel id for the current channel.
case TEST_OP_GET_THIS_CHANNEL_ID:
- REPLY_MESSAGE_RETURN(message, message.GetChannelId(), 0);
+ REPLY_MESSAGE_RETURN(message, message.GetChannelId(), {});
// Return the channel id for the test channel.
case TEST_OP_GET_TEST_CHANNEL_ID:
if (test_channel_)
- REPLY_MESSAGE_RETURN(message, test_channel_->channel_id(), 0);
+ REPLY_MESSAGE_RETURN(message, test_channel_->channel_id(), {});
else
- REPLY_ERROR_RETURN(message, ENOENT, 0);
+ REPLY_ERROR_RETURN(message, ENOENT, {});
// Test check channel feature.
case TEST_OP_CHECK_CHANNEL_ID: {
ChannelReference ref = 0;
- if (message.Read(&ref, sizeof(ref)) < static_cast<ssize_t>(sizeof(ref)))
- REPLY_ERROR_RETURN(message, EIO, 0);
+ if (!message.ReadAll(&ref, sizeof(ref)))
+ REPLY_ERROR_RETURN(message, EIO, {});
const Status<int> ret = message.CheckChannel<TestChannel>(ref, nullptr);
- REPLY_MESSAGE_RETURN(message, ret, 0);
+ REPLY_MESSAGE_RETURN(message, ret, {});
}
case TEST_OP_CHECK_CHANNEL_OBJECT: {
std::shared_ptr<TestChannel> channel;
ChannelReference ref = 0;
- if (message.Read(&ref, sizeof(ref)) < static_cast<ssize_t>(sizeof(ref)))
- REPLY_ERROR_RETURN(message, EIO, 0);
+ if (!message.ReadAll(&ref, sizeof(ref)))
+ REPLY_ERROR_RETURN(message, EIO, {});
const Status<int> ret =
message.CheckChannel<TestChannel>(ref, &channel);
if (!ret)
- REPLY_MESSAGE_RETURN(message, ret, 0);
+ REPLY_MESSAGE_RETURN(message, ret, {});
if (channel != nullptr)
- REPLY_MESSAGE_RETURN(message, channel->channel_id(), 0);
+ REPLY_MESSAGE_RETURN(message, channel->channel_id(), {});
else
- REPLY_ERROR_RETURN(message, ENODATA, 0);
+ REPLY_ERROR_RETURN(message, ENODATA, {});
}
case TEST_OP_CHECK_CHANNEL_FROM_OTHER_SERVICE: {
ChannelReference ref = 0;
- if (message.Read(&ref, sizeof(ref)) < static_cast<ssize_t>(sizeof(ref)))
- REPLY_ERROR_RETURN(message, EIO, 0);
+ if (!message.ReadAll(&ref, sizeof(ref)))
+ REPLY_ERROR_RETURN(message, EIO, {});
const Status<int> ret = message.CheckChannel<TestChannel>(
other_service_.get(), ref, nullptr);
- REPLY_MESSAGE_RETURN(message, ret, 0);
+ REPLY_MESSAGE_RETURN(message, ret, {});
}
case TEST_OP_GET_NEW_CHANNEL: {
auto channel = std::make_shared<TestChannel>(-1);
Status<RemoteChannelHandle> channel_handle =
message.PushChannel(0, channel, &channel->channel_id_);
- REPLY_MESSAGE_RETURN(message, channel_handle, 0);
+ REPLY_MESSAGE_RETURN(message, channel_handle, {});
}
case TEST_OP_GET_NEW_CHANNEL_FROM_OTHER_SERVICE: {
if (!other_service_)
- REPLY_ERROR_RETURN(message, EINVAL, 0);
+ REPLY_ERROR_RETURN(message, EINVAL, {});
auto channel = std::make_shared<TestChannel>(-1);
Status<RemoteChannelHandle> channel_handle = message.PushChannel(
other_service_.get(), 0, channel, &channel->channel_id_);
- REPLY_MESSAGE_RETURN(message, channel_handle, 0);
+ REPLY_MESSAGE_RETURN(message, channel_handle, {});
}
case TEST_OP_GET_THIS_PROCESS_ID:
- REPLY_MESSAGE_RETURN(message, message.GetProcessId(), 0);
+ REPLY_MESSAGE_RETURN(message, message.GetProcessId(), {});
case TEST_OP_GET_THIS_THREAD_ID:
- REPLY_MESSAGE_RETURN(message, message.GetThreadId(), 0);
+ REPLY_MESSAGE_RETURN(message, message.GetThreadId(), {});
case TEST_OP_GET_THIS_EUID:
- REPLY_MESSAGE_RETURN(message, message.GetEffectiveUserId(), 0);
+ REPLY_MESSAGE_RETURN(message, message.GetEffectiveUserId(), {});
case TEST_OP_GET_THIS_EGID:
- REPLY_MESSAGE_RETURN(message, message.GetEffectiveGroupId(), 0);
+ REPLY_MESSAGE_RETURN(message, message.GetEffectiveGroupId(), {});
case TEST_OP_POLLIN_FROM_SERVICE:
REPLY_MESSAGE_RETURN(message, message.ModifyChannelEvents(0, EPOLLIN),
- 0);
+ {});
case TEST_OP_SEND_LARGE_DATA_RETURN_SUM: {
std::array<int, kLargeDataSize> data_array;
- ssize_t size_to_read = data_array.size() * sizeof(int);
- ssize_t read = message.Read(data_array.data(), size_to_read);
- if (read < size_to_read)
- REPLY_ERROR_RETURN(message, EIO, 0);
+ size_t size_to_read = data_array.size() * sizeof(int);
+ if (!message.ReadAll(data_array.data(), size_to_read)) {
+ REPLY_ERROR_RETURN(message, EIO, {});
+ }
int sum = std::accumulate(data_array.begin(), data_array.end(), 0);
- REPLY_MESSAGE_RETURN(message, sum, 0);
+ REPLY_MESSAGE_RETURN(message, sum, {});
}
default:
@@ -245,7 +245,7 @@
TestService(const std::string& name,
const std::shared_ptr<TestService>& other_service, bool blocking)
: BASE(std::string("TestService") + name,
- Endpoint::Create(kTestServicePath + name, blocking)),
+ Endpoint::CreateAndBindSocket(kTestServicePath + name, blocking)),
other_service_(other_service),
service_id_(service_counter_++) {}
@@ -300,7 +300,7 @@
// Returns the channel id of the channel.
int CheckChannelIdArgument(BorrowedChannelHandle channel) {
Transaction trans{*this};
- ChannelReference ref = trans.PushChannelHandle(channel);
+ ChannelReference ref = trans.PushChannelHandle(channel).get();
return ReturnStatusOrError(trans.Send<int>(TEST_OP_CHECK_CHANNEL_ID, &ref,
sizeof(ref), nullptr, 0));
}
@@ -309,7 +309,7 @@
// Returns the channel id of the channel exercising the context pointer.
int CheckChannelObjectArgument(BorrowedChannelHandle channel) {
Transaction trans{*this};
- ChannelReference ref = trans.PushChannelHandle(channel);
+ ChannelReference ref = trans.PushChannelHandle(channel).get();
return ReturnStatusOrError(trans.Send<int>(TEST_OP_CHECK_CHANNEL_OBJECT,
&ref, sizeof(ref), nullptr, 0));
}
@@ -318,7 +318,7 @@
// Returns 0 on success.
int CheckChannelFromOtherService(BorrowedChannelHandle channel) {
Transaction trans{*this};
- ChannelReference ref = trans.PushChannelHandle(channel);
+ ChannelReference ref = trans.PushChannelHandle(channel).get();
return ReturnStatusOrError(
trans.Send<int>(TEST_OP_CHECK_CHANNEL_FROM_OTHER_SERVICE, &ref,
sizeof(ref), nullptr, 0));
diff --git a/libs/vr/libvrflinger/display_manager_service.cpp b/libs/vr/libvrflinger/display_manager_service.cpp
index e07901d..49b6f09 100644
--- a/libs/vr/libvrflinger/display_manager_service.cpp
+++ b/libs/vr/libvrflinger/display_manager_service.cpp
@@ -32,12 +32,12 @@
namespace dvr {
void DisplayManager::SetNotificationsPending(bool pending) {
- int ret = service_->ModifyChannelEvents(channel_id_, pending ? 0 : POLLIN,
- pending ? POLLIN : 0);
- ALOGE_IF(ret < 0,
+ auto status = service_->ModifyChannelEvents(channel_id_, pending ? 0 : POLLIN,
+ pending ? POLLIN : 0);
+ ALOGE_IF(!status,
"DisplayManager::SetNotificationPending: Failed to modify channel "
"events: %s",
- strerror(-ret));
+ status.GetErrorMessage().c_str());
}
DisplayManagerService::DisplayManagerService(
@@ -68,24 +68,24 @@
display_manager_ = nullptr;
}
-int DisplayManagerService::HandleMessage(pdx::Message& message) {
+pdx::Status<void> DisplayManagerService::HandleMessage(pdx::Message& message) {
auto channel = std::static_pointer_cast<DisplayManager>(message.GetChannel());
switch (message.GetOp()) {
case DisplayManagerRPC::GetSurfaceList::Opcode:
DispatchRemoteMethod<DisplayManagerRPC::GetSurfaceList>(
*this, &DisplayManagerService::OnGetSurfaceList, message);
- return 0;
+ return {};
case DisplayManagerRPC::UpdateSurfaces::Opcode:
DispatchRemoteMethod<DisplayManagerRPC::UpdateSurfaces>(
*this, &DisplayManagerService::OnUpdateSurfaces, message);
- return 0;
+ return {};
case DisplayManagerRPC::SetupPoseBuffer::Opcode:
DispatchRemoteMethod<DisplayManagerRPC::SetupPoseBuffer>(
*this, &DisplayManagerService::OnSetupPoseBuffer, message);
- return 0;
+ return {};
default:
return Service::DefaultHandleMessage(message);
@@ -189,7 +189,7 @@
}
pdx::BorrowedChannelHandle DisplayManagerService::OnSetupPoseBuffer(
- pdx::Message& message, size_t extended_region_size, int usage) {
+ pdx::Message& /*message*/, size_t extended_region_size, int usage) {
return display_service_->SetupPoseBuffer(extended_region_size, usage);
}
diff --git a/libs/vr/libvrflinger/display_manager_service.h b/libs/vr/libvrflinger/display_manager_service.h
index 19098c2..80324fd 100644
--- a/libs/vr/libvrflinger/display_manager_service.h
+++ b/libs/vr/libvrflinger/display_manager_service.h
@@ -42,7 +42,7 @@
std::shared_ptr<pdx::Channel> OnChannelOpen(pdx::Message& message) override;
void OnChannelClose(pdx::Message& message,
const std::shared_ptr<pdx::Channel>& channel) override;
- int HandleMessage(pdx::Message& message) override;
+ pdx::Status<void> HandleMessage(pdx::Message& message) override;
private:
friend BASE;
diff --git a/libs/vr/libvrflinger/display_service.cpp b/libs/vr/libvrflinger/display_service.cpp
index c079187..3750ea3 100644
--- a/libs/vr/libvrflinger/display_service.cpp
+++ b/libs/vr/libvrflinger/display_service.cpp
@@ -65,39 +65,39 @@
// First-level dispatch for display service messages. Directly handles messages
// that are independent of the display surface (metrics, creation) and routes
// surface-specific messages to the per-instance handlers.
-int DisplayService::HandleMessage(pdx::Message& message) {
+pdx::Status<void> DisplayService::HandleMessage(pdx::Message& message) {
auto channel = message.GetChannel<SurfaceChannel>();
switch (message.GetOp()) {
case DisplayRPC::GetMetrics::Opcode:
DispatchRemoteMethod<DisplayRPC::GetMetrics>(
*this, &DisplayService::OnGetMetrics, message);
- return 0;
+ return {};
case DisplayRPC::GetEdsCapture::Opcode:
DispatchRemoteMethod<DisplayRPC::GetEdsCapture>(
*this, &DisplayService::OnGetEdsCapture, message);
- return 0;
+ return {};
case DisplayRPC::CreateSurface::Opcode:
DispatchRemoteMethod<DisplayRPC::CreateSurface>(
*this, &DisplayService::OnCreateSurface, message);
- return 0;
+ return {};
case DisplayRPC::SetViewerParams::Opcode:
DispatchRemoteMethod<DisplayRPC::SetViewerParams>(
*this, &DisplayService::OnSetViewerParams, message);
- return 0;
+ return {};
case DisplayRPC::GetPoseBuffer::Opcode:
DispatchRemoteMethod<DisplayRPC::GetPoseBuffer>(
*this, &DisplayService::OnGetPoseBuffer, message);
- return 0;
+ return {};
case DisplayRPC::IsVrAppRunning::Opcode:
DispatchRemoteMethod<DisplayRPC::IsVrAppRunning>(
*this, &DisplayService::IsVrAppRunning, message);
- return 0;
+ return {};
// Direct the surface specific messages to the surface instance.
case DisplayRPC::CreateBufferQueue::Opcode:
@@ -265,7 +265,7 @@
// Calls the message handler for the DisplaySurface associated with this
// channel.
-int DisplayService::HandleSurfaceMessage(pdx::Message& message) {
+pdx::Status<void> DisplayService::HandleSurfaceMessage(pdx::Message& message) {
auto surface = std::static_pointer_cast<SurfaceChannel>(message.GetChannel());
ALOGW_IF(!surface,
"DisplayService::HandleSurfaceMessage: surface is nullptr!");
@@ -273,7 +273,7 @@
if (surface)
return surface->HandleMessage(message);
else
- REPLY_ERROR_RETURN(message, EINVAL, 0);
+ REPLY_ERROR_RETURN(message, EINVAL, {});
}
std::shared_ptr<DisplaySurface> DisplayService::GetDisplaySurface(
diff --git a/libs/vr/libvrflinger/display_service.h b/libs/vr/libvrflinger/display_service.h
index 8e96172..da80a84 100644
--- a/libs/vr/libvrflinger/display_service.h
+++ b/libs/vr/libvrflinger/display_service.h
@@ -27,7 +27,7 @@
void OnChannelClose(pdx::Message& message,
const std::shared_ptr<pdx::Channel>& channel) override;
- int HandleMessage(pdx::Message& message) override;
+ pdx::Status<void> HandleMessage(pdx::Message& message) override;
std::shared_ptr<DisplaySurface> GetDisplaySurface(int surface_id) const;
std::vector<std::shared_ptr<DisplaySurface>> GetDisplaySurfaces() const;
@@ -94,7 +94,7 @@
// the display manager should be notified.
void NotifyDisplayConfigurationUpdate();
- int HandleSurfaceMessage(pdx::Message& message);
+ pdx::Status<void> HandleSurfaceMessage(pdx::Message& message);
DisplayService(const DisplayService&) = delete;
void operator=(const DisplayService&) = delete;
diff --git a/libs/vr/libvrflinger/display_surface.cpp b/libs/vr/libvrflinger/display_surface.cpp
index 66e9925..a7220fe 100644
--- a/libs/vr/libvrflinger/display_surface.cpp
+++ b/libs/vr/libvrflinger/display_surface.cpp
@@ -206,7 +206,7 @@
return !acquired_buffers_.IsEmpty();
}
-int DisplaySurface::HandleMessage(pdx::Message& message) {
+pdx::Status<void> DisplaySurface::HandleMessage(pdx::Message& message) {
switch (message.GetOp()) {
case DisplayRPC::SetAttributes::Opcode:
DispatchRemoteMethod<DisplayRPC::SetAttributes>(
@@ -227,7 +227,7 @@
return SurfaceChannel::HandleMessage(message);
}
- return 0;
+ return {};
}
int DisplaySurface::OnClientSetAttributes(
@@ -301,7 +301,7 @@
pdx::Message& message) {
if (flags_ & DVR_DISPLAY_SURFACE_FLAGS_DISABLE_SYSTEM_DISTORTION) {
ALOGE(
- "DisplaySurface::OnCreateVideoMeshSurface: system distorion is "
+ "DisplaySurface::OnCreateVideoMeshSurface: system distortion is "
"disabled on this display surface, cannot create VideoMeshSurface on "
"top of it.");
REPLY_ERROR_RETURN(message, EINVAL, {});
@@ -309,22 +309,21 @@
int channel_id;
auto status = message.PushChannel(0, nullptr, &channel_id);
-
if (!status) {
ALOGE(
"DisplaySurface::OnCreateVideoMeshSurface: failed to push channel: %s",
status.GetErrorMessage().c_str());
- REPLY_ERROR_RETURN(message, ENOMEM, {});
+ REPLY_ERROR_RETURN(message, status.error(), {});
}
auto surface = std::make_shared<VideoMeshSurface>(service(), channel_id);
- const int ret = service()->SetChannel(channel_id, surface);
- if (ret < 0) {
+ auto channel_status = service()->SetChannel(channel_id, surface);
+ if (!channel_status) {
ALOGE(
"DisplaySurface::OnCreateVideoMeshSurface: failed to set new video "
"mesh surface channel: %s",
- strerror(-ret));
- REPLY_ERROR_RETURN(message, ENOMEM, {});
+ channel_status.GetErrorMessage().c_str());
+ REPLY_ERROR_RETURN(message, channel_status.error(), {});
}
{
diff --git a/libs/vr/libvrflinger/display_surface.h b/libs/vr/libvrflinger/display_surface.h
index d31a3a9..2e4cf75 100644
--- a/libs/vr/libvrflinger/display_surface.h
+++ b/libs/vr/libvrflinger/display_surface.h
@@ -106,7 +106,7 @@
// Dispatches display surface messages to the appropriate handlers. This
// handler runs on the displayd message dispatch thread.
- int HandleMessage(pdx::Message& message) override;
+ pdx::Status<void> HandleMessage(pdx::Message& message) override;
// Sets display surface's client-controlled attributes.
int OnClientSetAttributes(pdx::Message& message,
diff --git a/libs/vr/libvrflinger/screenshot_service.cpp b/libs/vr/libvrflinger/screenshot_service.cpp
index fd1c582..d14d588 100644
--- a/libs/vr/libvrflinger/screenshot_service.cpp
+++ b/libs/vr/libvrflinger/screenshot_service.cpp
@@ -19,17 +19,17 @@
ScreenshotService::~ScreenshotService() { instance_ = nullptr; }
-int ScreenshotService::HandleMessage(pdx::Message& message) {
+pdx::Status<void> ScreenshotService::HandleMessage(pdx::Message& message) {
switch (message.GetOp()) {
case DisplayScreenshotRPC::GetFormat::Opcode:
DispatchRemoteMethod<DisplayScreenshotRPC::GetFormat>(
*this, &ScreenshotService::OnGetFormat, message);
- return 0;
+ return {};
case DisplayScreenshotRPC::TakeScreenshot::Opcode:
DispatchRemoteMethod<DisplayScreenshotRPC::TakeScreenshot>(
*this, &ScreenshotService::OnTakeScreenshot, message);
- return 0;
+ return {};
default:
return Service::HandleMessage(message);
diff --git a/libs/vr/libvrflinger/screenshot_service.h b/libs/vr/libvrflinger/screenshot_service.h
index ec4c527..f59e872 100644
--- a/libs/vr/libvrflinger/screenshot_service.h
+++ b/libs/vr/libvrflinger/screenshot_service.h
@@ -38,7 +38,7 @@
public:
~ScreenshotService();
- int HandleMessage(pdx::Message& message) override;
+ pdx::Status<void> HandleMessage(pdx::Message& message) override;
// Returns true if there is a pending screenshot request.
bool IsScreenshotRequestPending() const {
diff --git a/libs/vr/libvrflinger/surface_channel.cpp b/libs/vr/libvrflinger/surface_channel.cpp
index 8aa220b..263b382 100644
--- a/libs/vr/libvrflinger/surface_channel.cpp
+++ b/libs/vr/libvrflinger/surface_channel.cpp
@@ -7,7 +7,7 @@
namespace android {
namespace dvr {
-int SurfaceChannel::HandleMessage(Message& message) {
+pdx::Status<void> SurfaceChannel::HandleMessage(Message& message) {
switch (message.GetOp()) {
case DisplayRPC::GetMetadataBuffer::Opcode:
DispatchRemoteMethod<DisplayRPC::GetMetadataBuffer>(
@@ -15,7 +15,7 @@
break;
}
- return 0;
+ return {};
}
BorrowedChannelHandle SurfaceChannel::OnGetMetadataBuffer(Message& message) {
diff --git a/libs/vr/libvrflinger/surface_channel.h b/libs/vr/libvrflinger/surface_channel.h
index 870e1a4..bb6b1c5 100644
--- a/libs/vr/libvrflinger/surface_channel.h
+++ b/libs/vr/libvrflinger/surface_channel.h
@@ -33,7 +33,7 @@
// Dispatches surface channel messages to the appropriate handlers. This
// handler runs on the displayd message dispatch thread.
- virtual int HandleMessage(pdx::Message& message);
+ virtual pdx::Status<void> HandleMessage(pdx::Message& message);
protected:
// Contains the surface metadata.
diff --git a/libs/vr/libvrflinger/video_mesh_surface.cpp b/libs/vr/libvrflinger/video_mesh_surface.cpp
index a961a3d..d915a4a 100644
--- a/libs/vr/libvrflinger/video_mesh_surface.cpp
+++ b/libs/vr/libvrflinger/video_mesh_surface.cpp
@@ -14,7 +14,7 @@
VideoMeshSurface::~VideoMeshSurface() {}
-int VideoMeshSurface::HandleMessage(Message& message) {
+pdx::Status<void> VideoMeshSurface::HandleMessage(Message& message) {
ATRACE_NAME("VideoMeshSurface::HandleMessage");
switch (message.GetOp()) {
@@ -27,7 +27,7 @@
return SurfaceChannel::HandleMessage(message);
}
- return 0;
+ return {};
}
std::shared_ptr<ConsumerQueue> VideoMeshSurface::GetConsumerQueue() {
diff --git a/libs/vr/libvrflinger/video_mesh_surface.h b/libs/vr/libvrflinger/video_mesh_surface.h
index 1370793..2c9f3e8 100644
--- a/libs/vr/libvrflinger/video_mesh_surface.h
+++ b/libs/vr/libvrflinger/video_mesh_surface.h
@@ -12,7 +12,7 @@
// VideoMeshSurface takes three inputs: 1) buffers filled by Android system
// components (e.g. MediaCodec or camera stack) other than applications' GL
-// context; 2) a 3D mesh choosen by application to define the shape of the
+// context; 2) a 3D mesh chosen by application to define the shape of the
// surface; 3) a transformation matrix from application to define the rotation,
// position, and scaling of the video surface.
class VideoMeshSurface : public SurfaceChannel {
@@ -33,7 +33,7 @@
}
}
- int HandleMessage(Message& message) override;
+ pdx::Status<void> HandleMessage(Message& message) override;
std::shared_ptr<ConsumerQueue> GetConsumerQueue();
diff --git a/libs/vr/libvrflinger/vsync_service.cpp b/libs/vr/libvrflinger/vsync_service.cpp
index 48fa2c2..612b9b2 100644
--- a/libs/vr/libvrflinger/vsync_service.cpp
+++ b/libs/vr/libvrflinger/vsync_service.cpp
@@ -107,26 +107,26 @@
}
}
-int VSyncService::HandleMessage(pdx::Message& message) {
+pdx::Status<void> VSyncService::HandleMessage(pdx::Message& message) {
switch (message.GetOp()) {
case DisplayVSyncRPC::Wait::Opcode:
AddWaiter(message);
- return 0;
+ return {};
case DisplayVSyncRPC::GetLastTimestamp::Opcode:
DispatchRemoteMethod<DisplayVSyncRPC::GetLastTimestamp>(
*this, &VSyncService::OnGetLastTimestamp, message);
- return 0;
+ return {};
case DisplayVSyncRPC::GetSchedInfo::Opcode:
DispatchRemoteMethod<DisplayVSyncRPC::GetSchedInfo>(
*this, &VSyncService::OnGetSchedInfo, message);
- return 0;
+ return {};
case DisplayVSyncRPC::Acknowledge::Opcode:
DispatchRemoteMethod<DisplayVSyncRPC::Acknowledge>(
*this, &VSyncService::OnAcknowledge, message);
- return 0;
+ return {};
default:
return Service::HandleMessage(message);
diff --git a/libs/vr/libvrflinger/vsync_service.h b/libs/vr/libvrflinger/vsync_service.h
index ba1d4df..1c86d42 100644
--- a/libs/vr/libvrflinger/vsync_service.h
+++ b/libs/vr/libvrflinger/vsync_service.h
@@ -56,7 +56,7 @@
public:
~VSyncService() override;
- int HandleMessage(pdx::Message& message) override;
+ pdx::Status<void> HandleMessage(pdx::Message& message) override;
std::shared_ptr<pdx::Channel> OnChannelOpen(pdx::Message& message) override;
void OnChannelClose(pdx::Message& message,
diff --git a/opengl/libs/EGL/egl_object.cpp b/opengl/libs/EGL/egl_object.cpp
index 7ed34be..6238780 100644
--- a/opengl/libs/EGL/egl_object.cpp
+++ b/opengl/libs/EGL/egl_object.cpp
@@ -114,7 +114,7 @@
// call the implementation's glGetString(GL_EXTENSIONS)
const char* exts = (const char *)gEGLImpl.hooks[version]->gl.glGetString(GL_EXTENSIONS);
gl_extensions = exts;
- if (gl_extensions.find("GL_EXT_debug_marker") != std::string::npos) {
+ if (gl_extensions.find("GL_EXT_debug_marker") == std::string::npos) {
gl_extensions.insert(0, "GL_EXT_debug_marker ");
}
diff --git a/services/sensorservice/hidl/Android.bp b/services/sensorservice/hidl/Android.bp
index f00c297..748dafc 100644
--- a/services/sensorservice/hidl/Android.bp
+++ b/services/sensorservice/hidl/Android.bp
@@ -1,6 +1,7 @@
cc_library_shared {
name: "libsensorservicehidl",
srcs: [
+ "EventQueue.cpp",
"DirectReportChannel.cpp",
"SensorManager.cpp",
"utils.cpp",
@@ -19,6 +20,9 @@
"android.hardware.sensors@1.0",
"android.hidl.base@1.0",
],
+ static_libs: [
+ "android.hardware.sensors@1.0-convert",
+ ],
export_include_dirs: [
"include/"
],
diff --git a/services/sensorservice/hidl/DirectReportChannel.cpp b/services/sensorservice/hidl/DirectReportChannel.cpp
index 9caba47..773ce8c 100644
--- a/services/sensorservice/hidl/DirectReportChannel.cpp
+++ b/services/sensorservice/hidl/DirectReportChannel.cpp
@@ -32,8 +32,9 @@
// Methods from ::android::frameworks::sensorservice::V1_0::IDirectReportChannel follow.
Return<Result> DirectReportChannel::configure(int32_t sensorHandle, RateLevel rate) {
- return convertResult(mManager.configureDirectChannel(mId,
- static_cast<int>(sensorHandle), static_cast<int>(rate)));
+ int token = mManager.configureDirectChannel(mId,
+ static_cast<int>(sensorHandle), static_cast<int>(rate));
+ return token <= 0 ? convertResult(token) : Result::OK;
}
diff --git a/services/sensorservice/hidl/DirectReportChannel.h b/services/sensorservice/hidl/DirectReportChannel.h
index f4cd4e7..9134944 100644
--- a/services/sensorservice/hidl/DirectReportChannel.h
+++ b/services/sensorservice/hidl/DirectReportChannel.h
@@ -41,7 +41,7 @@
using ::android::hardware::Void;
using ::android::sp;
-struct DirectReportChannel : public IDirectReportChannel {
+struct DirectReportChannel final : public IDirectReportChannel {
DirectReportChannel(::android::SensorManager& manager, int channelId);
~DirectReportChannel();
diff --git a/services/sensorservice/hidl/EventQueue.cpp b/services/sensorservice/hidl/EventQueue.cpp
new file mode 100644
index 0000000..86d365c
--- /dev/null
+++ b/services/sensorservice/hidl/EventQueue.cpp
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "EventQueue.h"
+#include "utils.h"
+
+#include <utils/Looper.h>
+
+namespace android {
+namespace frameworks {
+namespace sensorservice {
+namespace V1_0 {
+namespace implementation {
+
+class EventQueueLooperCallback : public ::android::LooperCallback {
+public:
+ EventQueueLooperCallback(sp<EventQueue> queue, sp<IEventQueueCallback> callback)
+ : mQueue(queue), mCallback(callback) {
+ }
+
+ int handleEvent(__unused int fd, __unused int events, __unused void* data) {
+
+ ASensorEvent event;
+ ssize_t actual;
+ const sp<::android::SensorEventQueue>& internalQueue = mQueue->mInternalQueue;
+
+ while ((actual = internalQueue->read(&event, 1 /* count */)) > 0) {
+ internalQueue->sendAck(&event, actual);
+ mCallback->onEvent(convertEvent(event));
+ }
+
+ return 1; // continue to receive callbacks
+ }
+
+private:
+ sp<EventQueue> mQueue;
+ sp<IEventQueueCallback> mCallback;
+};
+
+EventQueue::EventQueue(
+ sp<IEventQueueCallback> callback,
+ sp<::android::Looper> looper,
+ sp<::android::SensorEventQueue> internalQueue)
+ : mLooper(looper),
+ mInternalQueue(internalQueue) {
+
+ mLooper->addFd(mInternalQueue->getFd(), ALOOPER_POLL_CALLBACK, ALOOPER_EVENT_INPUT,
+ new EventQueueLooperCallback(this, callback), NULL /* data */);
+}
+
+EventQueue::~EventQueue() {
+ mLooper->removeFd(mInternalQueue->getFd());
+}
+
+// Methods from ::android::frameworks::sensorservice::V1_0::IEventQueue follow.
+Return<Result> EventQueue::enableSensor(int32_t sensorHandle, int32_t samplingPeriodUs,
+ int64_t maxBatchReportLatencyUs) {
+ // TODO implement
+ return convertResult(mInternalQueue->enableSensor(sensorHandle, samplingPeriodUs,
+ maxBatchReportLatencyUs, 0 /* reserved flags */));
+}
+
+Return<Result> EventQueue::disableSensor(int32_t sensorHandle) {
+ return convertResult(mInternalQueue->disableSensor(sensorHandle));
+}
+
+} // namespace implementation
+} // namespace V1_0
+} // namespace sensorservice
+} // namespace frameworks
+} // namespace android
diff --git a/services/sensorservice/hidl/EventQueue.h b/services/sensorservice/hidl/EventQueue.h
new file mode 100644
index 0000000..87c614b
--- /dev/null
+++ b/services/sensorservice/hidl/EventQueue.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2017 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_FRAMEWORKS_SENSORSERVICE_V1_0_EVENTQUEUE_H
+#define ANDROID_FRAMEWORKS_SENSORSERVICE_V1_0_EVENTQUEUE_H
+
+#include "SensorManager.h"
+
+#include <android/frameworks/sensorservice/1.0/IEventQueue.h>
+#include <android/frameworks/sensorservice/1.0/IEventQueueCallback.h>
+#include <hidl/MQDescriptor.h>
+#include <hidl/Status.h>
+#include <sensor/SensorManager.h>
+
+namespace android {
+namespace frameworks {
+namespace sensorservice {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::frameworks::sensorservice::V1_0::IEventQueue;
+using ::android::frameworks::sensorservice::V1_0::IEventQueueCallback;
+using ::android::frameworks::sensorservice::V1_0::Result;
+using ::android::hardware::Return;
+using ::android::sp;
+
+struct EventQueue final : public IEventQueue {
+ EventQueue(
+ sp<IEventQueueCallback> callback,
+ sp<::android::Looper> looper,
+ sp<::android::SensorEventQueue> internalQueue);
+ ~EventQueue();
+
+ // Methods from ::android::frameworks::sensorservice::V1_0::IEventQueue follow.
+ Return<Result> enableSensor(int32_t sensorHandle, int32_t samplingPeriodUs, int64_t maxBatchReportLatencyUs) override;
+ Return<Result> disableSensor(int32_t sensorHandle) override;
+
+private:
+ friend class EventQueueLooperCallback;
+ sp<::android::Looper> mLooper;
+ sp<::android::SensorEventQueue> mInternalQueue;
+};
+
+} // namespace implementation
+} // namespace V1_0
+} // namespace sensorservice
+} // namespace frameworks
+} // namespace android
+
+#endif // ANDROID_FRAMEWORKS_SENSORSERVICE_V1_0_EVENTQUEUE_H
diff --git a/services/sensorservice/hidl/SensorManager.cpp b/services/sensorservice/hidl/SensorManager.cpp
index 37e53dc..0743fc3 100644
--- a/services/sensorservice/hidl/SensorManager.cpp
+++ b/services/sensorservice/hidl/SensorManager.cpp
@@ -20,10 +20,14 @@
#endif
#include <android-base/logging.h>
-#include "DirectReportChannel.h"
#include "SensorManager.h"
+
+#include "EventQueue.h"
+#include "DirectReportChannel.h"
#include "utils.h"
+#include <thread>
+
namespace android {
namespace frameworks {
namespace sensorservice {
@@ -31,19 +35,28 @@
namespace implementation {
using ::android::hardware::sensors::V1_0::SensorInfo;
+using ::android::hardware::sensors::V1_0::SensorsEventFormatOffset;
using ::android::hardware::hidl_vec;
using ::android::hardware::Void;
using ::android::sp;
SensorManager::SensorManager()
- : mManager{::android::SensorManager::getInstanceForPackage(
+ : mInternalManager{::android::SensorManager::getInstanceForPackage(
String16(ISensorManager::descriptor))} {
}
+SensorManager::~SensorManager() {
+ // Stops pollAll inside the thread.
+ std::unique_lock<std::mutex> lock(mLooperMutex);
+ if (mLooper != nullptr) {
+ mLooper->wake();
+ }
+}
+
// Methods from ::android::frameworks::sensorservice::V1_0::ISensorManager follow.
Return<void> SensorManager::getSensorList(getSensorList_cb _hidl_cb) {
::android::Sensor const* const* list;
- ssize_t count = mManager.getSensorList(&list);
+ ssize_t count = mInternalManager.getSensorList(&list);
if (count < 0 || !list) {
LOG(ERROR) << "::android::SensorManager::getSensorList encounters " << count;
_hidl_cb({}, Result::UNKNOWN_ERROR);
@@ -59,7 +72,7 @@
}
Return<void> SensorManager::getDefaultSensor(SensorType type, getDefaultSensor_cb _hidl_cb) {
- ::android::Sensor const* sensor = mManager.getDefaultSensor(static_cast<int>(type));
+ ::android::Sensor const* sensor = mInternalManager.getDefaultSensor(static_cast<int>(type));
if (!sensor) {
_hidl_cb({}, Result::NOT_EXIST);
return Void();
@@ -90,12 +103,12 @@
Return<void> SensorManager::createAshmemDirectChannel(
const hidl_memory& mem, uint64_t size,
createAshmemDirectChannel_cb _hidl_cb) {
- if (size > mem.size()) {
+ if (size > mem.size() || size < (uint64_t)SensorsEventFormatOffset::TOTAL_LENGTH) {
_hidl_cb(nullptr, Result::BAD_VALUE);
return Void();
}
- createDirectChannel(mManager, size, SENSOR_DIRECT_MEM_TYPE_ASHMEM,
+ createDirectChannel(mInternalManager, size, SENSOR_DIRECT_MEM_TYPE_ASHMEM,
mem.handle(), _hidl_cb);
return Void();
@@ -105,16 +118,53 @@
const hidl_handle& buffer, uint64_t size,
createGrallocDirectChannel_cb _hidl_cb) {
- createDirectChannel(mManager, size, SENSOR_DIRECT_MEM_TYPE_GRALLOC,
+ createDirectChannel(mInternalManager, size, SENSOR_DIRECT_MEM_TYPE_GRALLOC,
buffer.getNativeHandle(), _hidl_cb);
return Void();
}
+/* One global looper for all event queues created from this SensorManager. */
+sp<::android::Looper> SensorManager::getLooper() {
+ std::unique_lock<std::mutex> lock(mLooperMutex);
+ if (mLooper == nullptr) {
+ std::condition_variable looperSet;
+
+ std::thread{[&mutex = mLooperMutex, &looper = mLooper, &looperSet] {
+ std::unique_lock<std::mutex> lock(mutex);
+ looper = Looper::prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS /* opts */);
+ lock.unlock();
+
+ looperSet.notify_one();
+ int pollResult = looper->pollAll(-1 /* timeout */);
+ if (pollResult != ALOOPER_POLL_WAKE) {
+ LOG(ERROR) << "Looper::pollAll returns unexpected " << pollResult;
+ }
+ LOG(INFO) << "Looper thread is terminated.";
+ }}.detach();
+ looperSet.wait(lock, [this]{ return this->mLooper != nullptr; });
+ }
+ return mLooper;
+}
+
Return<void> SensorManager::createEventQueue(
- __unused const sp<IEventQueueCallback> &callback, createEventQueue_cb _hidl_cb) {
- // TODO(b/35219747) Implement this
- _hidl_cb(nullptr, Result::UNKNOWN_ERROR);
+ const sp<IEventQueueCallback> &callback, createEventQueue_cb _hidl_cb) {
+ if (callback == nullptr) {
+ _hidl_cb(nullptr, Result::BAD_VALUE);
+ return Void();
+ }
+
+ sp<::android::Looper> looper = getLooper();
+ sp<::android::SensorEventQueue> internalQueue = mInternalManager.createEventQueue();
+ if (internalQueue == nullptr) {
+ LOG(WARNING) << "::android::SensorManager::createEventQueue returns nullptr.";
+ _hidl_cb(nullptr, Result::UNKNOWN_ERROR);
+ return Void();
+ }
+
+ sp<IEventQueue> queue = new EventQueue(callback, looper, internalQueue);
+ _hidl_cb(queue, Result::OK);
+
return Void();
}
diff --git a/services/sensorservice/hidl/include/sensorservicehidl/SensorManager.h b/services/sensorservice/hidl/include/sensorservicehidl/SensorManager.h
index 0b026c9..a2372df 100644
--- a/services/sensorservice/hidl/include/sensorservicehidl/SensorManager.h
+++ b/services/sensorservice/hidl/include/sensorservicehidl/SensorManager.h
@@ -17,11 +17,14 @@
#ifndef ANDROID_FRAMEWORKS_SENSORSERVICE_V1_0_SENSORMANAGER_H
#define ANDROID_FRAMEWORKS_SENSORSERVICE_V1_0_SENSORMANAGER_H
+#include <mutex>
+
#include <android/frameworks/sensorservice/1.0/ISensorManager.h>
#include <android/frameworks/sensorservice/1.0/types.h>
#include <hidl/MQDescriptor.h>
#include <hidl/Status.h>
#include <sensor/SensorManager.h>
+#include <utils/Looper.h>
namespace android {
namespace frameworks {
@@ -34,9 +37,10 @@
using ::android::hardware::hidl_memory;
using ::android::hardware::Return;
-struct SensorManager : public ISensorManager {
+struct SensorManager final : public ISensorManager {
SensorManager();
+ ~SensorManager();
// Methods from ::android::frameworks::sensorservice::V1_0::ISensorManager follow.
Return<void> getSensorList(getSensorList_cb _hidl_cb) override;
@@ -44,9 +48,13 @@
Return<void> createAshmemDirectChannel(const hidl_memory& mem, uint64_t size, createAshmemDirectChannel_cb _hidl_cb) override;
Return<void> createGrallocDirectChannel(const hidl_handle& buffer, uint64_t size, createGrallocDirectChannel_cb _hidl_cb) override;
Return<void> createEventQueue(const sp<IEventQueueCallback> &callback, createEventQueue_cb _hidl_cb);
-private:
- ::android::SensorManager& mManager;
+private:
+ sp<::android::Looper> getLooper();
+
+ ::android::SensorManager& mInternalManager;
+ std::mutex mLooperMutex;
+ sp<::android::Looper> mLooper;
};
} // namespace implementation
diff --git a/services/sensorservice/hidl/utils.cpp b/services/sensorservice/hidl/utils.cpp
index 4e02741..b540525 100644
--- a/services/sensorservice/hidl/utils.cpp
+++ b/services/sensorservice/hidl/utils.cpp
@@ -16,6 +16,8 @@
#include "utils.h"
+#include <sensors/convert.h>
+
namespace android {
namespace frameworks {
namespace sensorservice {
@@ -26,7 +28,7 @@
using ::android::hardware::hidl_string;
using ::android::hardware::sensors::V1_0::SensorInfo;
-SensorInfo convertSensor(const Sensor &src) {
+SensorInfo convertSensor(const Sensor& src) {
SensorInfo dst;
const String8& name = src.getName();
const String8& vendor = src.getVendor();
@@ -36,7 +38,7 @@
dst.sensorHandle = src.getHandle();
dst.type = static_cast<::android::hardware::sensors::V1_0::SensorType>(
src.getType());
- // FIXME maxRange uses maxValue because ::android::Sensor wraps the
+ // maxRange uses maxValue because ::android::Sensor wraps the
// internal sensor_t in this way.
dst.maxRange = src.getMaxValue();
dst.resolution = src.getResolution();
@@ -70,6 +72,13 @@
}
}
+::android::hardware::sensors::V1_0::Event convertEvent(const ::ASensorEvent& src) {
+ ::android::hardware::sensors::V1_0::Event dst;
+ ::android::hardware::sensors::V1_0::implementation::convertFromSensorEvent(
+ reinterpret_cast<const sensors_event_t&>(src), &dst);
+ return dst;
+}
+
} // namespace implementation
} // namespace V1_0
} // namespace sensorservice
diff --git a/services/sensorservice/hidl/utils.h b/services/sensorservice/hidl/utils.h
index 0606e69..b350928 100644
--- a/services/sensorservice/hidl/utils.h
+++ b/services/sensorservice/hidl/utils.h
@@ -30,6 +30,8 @@
::android::hardware::sensors::V1_0::SensorInfo convertSensor(const ::android::Sensor &src);
Result convertResult(status_t status);
+::android::hardware::sensors::V1_0::Event convertEvent(const ::ASensorEvent &event);
+
} // namespace implementation
} // namespace V1_0
} // namespace sensorservice
diff --git a/services/surfaceflinger/surfaceflinger.rc b/services/surfaceflinger/surfaceflinger.rc
index 435aa0c..0b482f7 100644
--- a/services/surfaceflinger/surfaceflinger.rc
+++ b/services/surfaceflinger/surfaceflinger.rc
@@ -1,5 +1,5 @@
service surfaceflinger /system/bin/surfaceflinger
- class core
+ class core animation
user system
group graphics drmrpc readproc
onrestart restart zygote
diff --git a/services/vr/bufferhubd/buffer_hub.cpp b/services/vr/bufferhubd/buffer_hub.cpp
index 80efcf8..de4950e 100644
--- a/services/vr/bufferhubd/buffer_hub.cpp
+++ b/services/vr/bufferhubd/buffer_hub.cpp
@@ -189,7 +189,7 @@
channel->HandleImpulse(message);
}
-int BufferHubService::HandleMessage(Message& message) {
+pdx::Status<void> BufferHubService::HandleMessage(Message& message) {
ATRACE_NAME("BufferHubService::HandleMessage");
auto channel = message.GetChannel<BufferHubChannel>();
@@ -207,22 +207,22 @@
case BufferHubRPC::CreateBuffer::Opcode:
DispatchRemoteMethod<BufferHubRPC::CreateBuffer>(
*this, &BufferHubService::OnCreateBuffer, message);
- return 0;
+ return {};
case BufferHubRPC::CreatePersistentBuffer::Opcode:
DispatchRemoteMethod<BufferHubRPC::CreatePersistentBuffer>(
*this, &BufferHubService::OnCreatePersistentBuffer, message);
- return 0;
+ return {};
case BufferHubRPC::GetPersistentBuffer::Opcode:
DispatchRemoteMethod<BufferHubRPC::GetPersistentBuffer>(
*this, &BufferHubService::OnGetPersistentBuffer, message);
- return 0;
+ return {};
case BufferHubRPC::CreateProducerQueue::Opcode:
DispatchRemoteMethod<BufferHubRPC::CreateProducerQueue>(
*this, &BufferHubService::OnCreateProducerQueue, message);
- return 0;
+ return {};
default:
return DefaultHandleMessage(message);
@@ -438,11 +438,11 @@
"BufferHubChannel::SignalAvailable: channel_id=%d buffer_id=%d",
channel_id(), buffer_id());
if (!IsDetached()) {
- const int ret = service_->ModifyChannelEvents(channel_id_, 0, POLLIN);
- ALOGE_IF(ret < 0,
+ const auto status = service_->ModifyChannelEvents(channel_id_, 0, POLLIN);
+ ALOGE_IF(!status,
"BufferHubChannel::SignalAvailable: failed to signal availability "
"channel_id=%d: %s",
- channel_id_, strerror(-ret));
+ channel_id_, status.GetErrorMessage().c_str());
} else {
ALOGD_IF(TRACE, "BufferHubChannel::SignalAvailable: detached buffer.");
}
@@ -454,11 +454,11 @@
"BufferHubChannel::ClearAvailable: channel_id=%d buffer_id=%d",
channel_id(), buffer_id());
if (!IsDetached()) {
- const int ret = service_->ModifyChannelEvents(channel_id_, POLLIN, 0);
- ALOGE_IF(ret < 0,
+ const auto status = service_->ModifyChannelEvents(channel_id_, POLLIN, 0);
+ ALOGE_IF(!status,
"BufferHubChannel::ClearAvailable: failed to clear availability "
"channel_id=%d: %s",
- channel_id_, strerror(-ret));
+ channel_id_, status.GetErrorMessage().c_str());
} else {
ALOGD_IF(TRACE, "BufferHubChannel::ClearAvailable: detached buffer.");
}
@@ -469,11 +469,11 @@
ALOGD_IF(TRACE, "BufferHubChannel::Hangup: channel_id=%d buffer_id=%d",
channel_id(), buffer_id());
if (!IsDetached()) {
- const int ret = service_->ModifyChannelEvents(channel_id_, 0, POLLHUP);
+ const auto status = service_->ModifyChannelEvents(channel_id_, 0, POLLHUP);
ALOGE_IF(
- ret < 0,
+ !status,
"BufferHubChannel::Hangup: failed to signal hangup channel_id=%d: %s",
- channel_id_, strerror(-ret));
+ channel_id_, status.GetErrorMessage().c_str());
} else {
ALOGD_IF(TRACE, "BufferHubChannel::Hangup: detached buffer.");
}
diff --git a/services/vr/bufferhubd/buffer_hub.h b/services/vr/bufferhubd/buffer_hub.h
index 28cb468..8a7dca8 100644
--- a/services/vr/bufferhubd/buffer_hub.h
+++ b/services/vr/bufferhubd/buffer_hub.h
@@ -141,7 +141,7 @@
BufferHubService();
~BufferHubService() override;
- int HandleMessage(pdx::Message& message) override;
+ pdx::Status<void> HandleMessage(pdx::Message& message) override;
void HandleImpulse(pdx::Message& message) override;
void OnChannelClose(pdx::Message& message,
diff --git a/services/vr/bufferhubd/producer_channel.cpp b/services/vr/bufferhubd/producer_channel.cpp
index 43010b0..903d174 100644
--- a/services/vr/bufferhubd/producer_channel.cpp
+++ b/services/vr/bufferhubd/producer_channel.cpp
@@ -161,12 +161,12 @@
auto consumer = std::make_shared<ConsumerChannel>(
service(), buffer_id(), channel_id, shared_from_this());
- const int ret = service()->SetChannel(channel_id, consumer);
- if (ret < 0) {
+ const auto channel_status = service()->SetChannel(channel_id, consumer);
+ if (!channel_status) {
ALOGE(
"ProducerChannel::CreateConsumer: failed to set new consumer channel: "
"%s",
- strerror(-ret));
+ channel_status.GetErrorMessage().c_str());
return RemoteChannelHandle();
}
diff --git a/services/vr/bufferhubd/producer_queue_channel.cpp b/services/vr/bufferhubd/producer_queue_channel.cpp
index 08f1e9d..7952642 100644
--- a/services/vr/bufferhubd/producer_queue_channel.cpp
+++ b/services/vr/bufferhubd/producer_queue_channel.cpp
@@ -97,18 +97,18 @@
"ProducerQueueChannel::OnCreateConsumerQueue: failed to push consumer "
"channel: %s",
status.GetErrorMessage().c_str());
- REPLY_ERROR_RETURN(message, ENOMEM, {});
+ REPLY_ERROR_RETURN(message, status.error(), {});
}
- const int ret = service()->SetChannel(
+ const auto channel_status = service()->SetChannel(
channel_id, std::make_shared<ConsumerQueueChannel>(
service(), buffer_id(), channel_id, shared_from_this()));
- if (ret < 0) {
+ if (!channel_status) {
ALOGE(
"ProducerQueueChannel::OnCreateConsumerQueue: failed to set new "
"consumer channel: %s",
- strerror(-ret));
- REPLY_ERROR_RETURN(message, ENOMEM, {});
+ channel_status.GetErrorMessage().c_str());
+ REPLY_ERROR_RETURN(message, channel_status.error(), {});
}
return std::make_pair(status.take(), meta_size_bytes_);
@@ -214,12 +214,13 @@
"ProducerQueueChannel::AllocateBuffer: buffer_id=%d, buffer_handle=%d",
buffer_id, buffer_handle.value());
- const int ret = service()->SetChannel(buffer_id, producer_channel);
- if (ret < 0) {
+ const auto channel_status =
+ service()->SetChannel(buffer_id, producer_channel);
+ if (!channel_status) {
ALOGE(
- "ProducerQueueChannel::AllocateBuffer: failed to set prodcuer channel "
+ "ProducerQueueChannel::AllocateBuffer: failed to set producer channel "
"for new BufferHubBuffer: %s",
- strerror(-ret));
+ channel_status.GetErrorMessage().c_str());
return {};
}
@@ -252,7 +253,7 @@
return {std::move(buffer_handle), slot};
}
-int ProducerQueueChannel::OnProducerQueueDetachBuffer(Message& message,
+int ProducerQueueChannel::OnProducerQueueDetachBuffer(Message& /*message*/,
size_t slot) {
if (buffers_[slot].expired()) {
ALOGE(
diff --git a/services/vr/hardware_composer/Android.bp b/services/vr/hardware_composer/Android.bp
index 1601c7f..629d65b 100644
--- a/services/vr/hardware_composer/Android.bp
+++ b/services/vr/hardware_composer/Android.bp
@@ -75,31 +75,6 @@
],
}
-cc_library_static {
- name: "libdvr_hwc",
- srcs: [
- "dvr_hardware_composer_client.cpp",
- ],
- static_libs: [
- "libvr_hwc-impl",
- // NOTE: This needs to be included after the *-impl lib otherwise the
- // symbols in the *-binder library get optimized out.
- "libvr_hwc-binder",
- ],
- shared_libs: [
- "libbase",
- "libbinder",
- "liblog",
- "libnativewindow",
- "libui",
- "libutils",
- ],
- export_include_dirs: ["private"],
- export_shared_lib_headers: [
- "libnativewindow",
- ],
-}
-
cc_test {
name: "vr_hwc_test",
gtest: true,
diff --git a/services/vr/hardware_composer/aidl/android/dvr/parcelable_composer_layer.cpp b/services/vr/hardware_composer/aidl/android/dvr/parcelable_composer_layer.cpp
index 34e2b7e..999d71e 100644
--- a/services/vr/hardware_composer/aidl/android/dvr/parcelable_composer_layer.cpp
+++ b/services/vr/hardware_composer/aidl/android/dvr/parcelable_composer_layer.cpp
@@ -34,9 +34,9 @@
// capability. Otherwise assume a count of 1.
mapper.getLayerCount(handle, &layer_count);
- sp<GraphicBuffer> buffer = new GraphicBuffer(
- width, height, format, layer_count, producer_usage, consumer_usage,
- stride, handle, true);
+ sp<GraphicBuffer> buffer = new GraphicBuffer(handle,
+ GraphicBuffer::TAKE_HANDLE, width, height, format, layer_count,
+ producer_usage, consumer_usage, stride);
return buffer;
}
diff --git a/services/vr/hardware_composer/vr_hwc.rc b/services/vr/hardware_composer/vr_hwc.rc
index 5d3c4f7..52d4da8 100644
--- a/services/vr/hardware_composer/vr_hwc.rc
+++ b/services/vr/hardware_composer/vr_hwc.rc
@@ -3,4 +3,3 @@
user system
group system graphics
onrestart restart surfaceflinger
- disabled
diff --git a/services/vr/performanced/performance_service.cpp b/services/vr/performanced/performance_service.cpp
index c99c8d4..955c661 100644
--- a/services/vr/performanced/performance_service.cpp
+++ b/services/vr/performanced/performance_service.cpp
@@ -170,22 +170,22 @@
return task.GetCpuSetPath();
}
-int PerformanceService::HandleMessage(Message& message) {
+pdx::Status<void> PerformanceService::HandleMessage(Message& message) {
switch (message.GetOp()) {
case PerformanceRPC::SetCpuPartition::Opcode:
DispatchRemoteMethod<PerformanceRPC::SetSchedulerClass>(
*this, &PerformanceService::OnSetCpuPartition, message);
- return 0;
+ return {};
case PerformanceRPC::SetSchedulerClass::Opcode:
DispatchRemoteMethod<PerformanceRPC::SetSchedulerClass>(
*this, &PerformanceService::OnSetSchedulerClass, message);
- return 0;
+ return {};
case PerformanceRPC::GetCpuPartition::Opcode:
DispatchRemoteMethod<PerformanceRPC::GetCpuPartition>(
*this, &PerformanceService::OnGetCpuPartition, message);
- return 0;
+ return {};
default:
return Service::HandleMessage(message);
diff --git a/services/vr/performanced/performance_service.h b/services/vr/performanced/performance_service.h
index e32d834..34abba7 100644
--- a/services/vr/performanced/performance_service.h
+++ b/services/vr/performanced/performance_service.h
@@ -17,7 +17,7 @@
// achieve system performance goals.
class PerformanceService : public pdx::ServiceBase<PerformanceService> {
public:
- int HandleMessage(pdx::Message& message) override;
+ pdx::Status<void> HandleMessage(pdx::Message& message) override;
bool IsInitialized() const override;
std::string DumpState(size_t max_length) override;
diff --git a/services/vr/sensord/pose_service.cpp b/services/vr/sensord/pose_service.cpp
index 2c4fc30..3cd5297 100644
--- a/services/vr/sensord/pose_service.cpp
+++ b/services/vr/sensord/pose_service.cpp
@@ -476,8 +476,8 @@
}
}
-int PoseService::HandleMessage(pdx::Message& msg) {
- int ret = 0;
+pdx::Status<void> PoseService::HandleMessage(pdx::Message& msg) {
+ pdx::Status<void> ret;
const pdx::MessageInfo& info = msg.GetInfo();
switch (info.op) {
case DVR_POSE_NOTIFY_VSYNC: {
@@ -495,21 +495,13 @@
{.iov_base = &right_eye_photon_offset_ns_,
.iov_len = sizeof(right_eye_photon_offset_ns_)},
};
- constexpr int expected_size =
- sizeof(vsync_count_) + sizeof(photon_timestamp_) +
- sizeof(display_period_ns_) + sizeof(right_eye_photon_offset_ns_);
- ret = msg.ReadVector(data, sizeof(data) / sizeof(data[0]));
- if (ret < expected_size) {
- ALOGI("error: msg.Read read too little (%d < %d)", ret, expected_size);
- REPLY_ERROR(msg, EIO, error);
- }
-
- if (!enable_external_pose_) {
+ ret = msg.ReadVectorAll(data);
+ if (ret && !enable_external_pose_) {
mapped_pose_buffer_->vsync_count = vsync_count_;
}
// TODO(jbates, eieio): make this async, no need to reply.
- REPLY_SUCCESS(msg, 0, error);
+ REPLY_MESSAGE(msg, ret, error);
}
case DVR_POSE_POLL: {
ATRACE_NAME("pose_poll");
@@ -535,61 +527,43 @@
Btrace("Pose polled");
- ret = msg.Write(&client_state, sizeof(client_state));
- const int expected_size = sizeof(client_state);
- if (ret < expected_size) {
- ALOGI("error: msg.Write wrote too little (%d < %d)", ret,
- expected_size);
- REPLY_ERROR(msg, EIO, error);
- }
- REPLY_SUCCESS(msg, 0, error);
+ ret = msg.WriteAll(&client_state, sizeof(client_state));
+ REPLY_MESSAGE(msg, ret, error);
}
case DVR_POSE_FREEZE: {
{
std::lock_guard<std::mutex> guard(mutex_);
DvrPoseState frozen_state;
- const int expected_size = sizeof(frozen_state);
- ret = msg.Read(&frozen_state, expected_size);
- if (ret < expected_size) {
- ALOGI("error: msg.Read read too little (%d < %d)", ret,
- expected_size);
- REPLY_ERROR(msg, EIO, error);
+ ret = msg.ReadAll(&frozen_state, sizeof(frozen_state));
+ if (!ret) {
+ REPLY_ERROR(msg, ret.error(), error);
}
frozen_state_ = frozen_state;
}
SetPoseMode(DVR_POSE_MODE_MOCK_FROZEN);
- REPLY_SUCCESS(msg, 0, error);
+ REPLY_MESSAGE(msg, ret, error);
}
case DVR_POSE_SET_MODE: {
int mode;
{
std::lock_guard<std::mutex> guard(mutex_);
- const int expected_size = sizeof(mode);
- ret = msg.Read(&mode, expected_size);
- if (ret < expected_size) {
- ALOGI("error: msg.Read read too little (%d < %d)", ret,
- expected_size);
- REPLY_ERROR(msg, EIO, error);
+ ret = msg.ReadAll(&mode, sizeof(mode));
+ if (!ret) {
+ REPLY_ERROR(msg, ret.error(), error);
}
if (mode < 0 || mode >= DVR_POSE_MODE_COUNT) {
REPLY_ERROR(msg, EINVAL, error);
}
}
SetPoseMode(DvrPoseMode(mode));
- REPLY_SUCCESS(msg, 0, error);
+ REPLY_MESSAGE(msg, ret, error);
}
case DVR_POSE_GET_MODE: {
std::lock_guard<std::mutex> guard(mutex_);
int mode = pose_mode_;
- ret = msg.Write(&mode, sizeof(mode));
- const int expected_size = sizeof(mode);
- if (ret < expected_size) {
- ALOGI("error: msg.Write wrote too little (%d < %d)", ret,
- expected_size);
- REPLY_ERROR(msg, EIO, error);
- }
- REPLY_SUCCESS(msg, 0, error);
+ ret = msg.WriteAll(&mode, sizeof(mode));
+ REPLY_MESSAGE(msg, ret, error);
}
case DVR_POSE_GET_RING_BUFFER: {
std::lock_guard<std::mutex> guard(mutex_);
diff --git a/services/vr/sensord/pose_service.h b/services/vr/sensord/pose_service.h
index 4df5036..fdd29b5 100644
--- a/services/vr/sensord/pose_service.h
+++ b/services/vr/sensord/pose_service.h
@@ -27,7 +27,7 @@
~PoseService() override;
bool IsInitialized() const override;
- int HandleMessage(pdx::Message& msg) override;
+ pdx::Status<void> HandleMessage(pdx::Message& msg) override;
std::string DumpState(size_t max_length) override;
// Handle events from the sensor HAL.
diff --git a/services/vr/sensord/sensor_service.cpp b/services/vr/sensord/sensor_service.cpp
index 1b809b0..a182a26 100644
--- a/services/vr/sensord/sensor_service.cpp
+++ b/services/vr/sensord/sensor_service.cpp
@@ -69,8 +69,8 @@
client->unset_sensor();
}
-int SensorService::HandleMessage(pdx::Message& msg) {
- int ret = 0;
+pdx::Status<void> SensorService::HandleMessage(pdx::Message& msg) {
+ pdx::Status<void> ret;
const pdx::MessageInfo& info = msg.GetInfo();
switch (info.op) {
case DVR_SENSOR_START: {
@@ -82,8 +82,7 @@
if (client->has_sensor())
REPLY_ERROR(msg, EINVAL, error);
int sensor_type;
- if (msg.Read(&sensor_type, sizeof(sensor_type)) <
- (ssize_t)sizeof(sensor_type))
+ if (!msg.ReadAll(&sensor_type, sizeof(sensor_type)))
REPLY_ERROR(msg, EIO, error);
// Find the sensor of the requested type.
@@ -120,10 +119,8 @@
{.iov_base = out_buffer,
.iov_len = num_events * sizeof(sensors_event_t)},
};
- ret = msg.WriteVector(svec, 2);
- int expected_size = sizeof(int) + num_events * sizeof(sensors_event_t);
- if (ret < expected_size) {
- ALOGI("error: msg.WriteVector wrote too little.");
+ ret = msg.WriteVectorAll(svec, 2);
+ if (!ret) {
REPLY_ERROR(msg, EIO, error);
}
REPLY_SUCCESS(msg, 0, error);
diff --git a/services/vr/sensord/sensor_service.h b/services/vr/sensord/sensor_service.h
index c35fada..6ea470b 100644
--- a/services/vr/sensord/sensor_service.h
+++ b/services/vr/sensord/sensor_service.h
@@ -22,7 +22,7 @@
*/
class SensorService : public pdx::ServiceBase<SensorService> {
public:
- int HandleMessage(pdx::Message& msg) override;
+ pdx::Status<void> HandleMessage(pdx::Message& msg) override;
std::shared_ptr<pdx::Channel> OnChannelOpen(pdx::Message& msg) override;
void OnChannelClose(pdx::Message& msg,
const std::shared_ptr<pdx::Channel>& chan) override;
diff --git a/services/vr/vr_window_manager/Android.bp b/services/vr/vr_window_manager/Android.bp
index a7a341c..0406331 100644
--- a/services/vr/vr_window_manager/Android.bp
+++ b/services/vr/vr_window_manager/Android.bp
@@ -41,6 +41,7 @@
"libperformance",
"libpdx_default_transport",
"libcutils",
+ "libvr_hwc-binder",
"libvr_manager",
"libvirtualtouchpadclient",
]
diff --git a/services/vr/vr_window_manager/composer/impl/vr_hwc.cpp b/services/vr/vr_window_manager/composer/impl/vr_hwc.cpp
index 3393ade..d142729 100644
--- a/services/vr/vr_window_manager/composer/impl/vr_hwc.cpp
+++ b/services/vr/vr_window_manager/composer/impl/vr_hwc.cpp
@@ -69,11 +69,10 @@
mapper.getLayerCount(handle, &layer_count);
// NOTE: Can't re-use |handle| since we don't own it.
- sp<GraphicBuffer> buffer = new GraphicBuffer(
- width, height, format, layer_count, producer_usage, consumer_usage,
- stride, native_handle_clone(handle), true);
- // Need to register the cloned buffer otherwise it can't be used later on.
- if (mapper.registerBuffer(buffer.get()) != OK) {
+ sp<GraphicBuffer> buffer = new GraphicBuffer(handle,
+ GraphicBuffer::CLONE_HANDLE, width, height, format, layer_count,
+ producer_usage, consumer_usage, stride);
+ if (buffer->initCheck() != OK) {
ALOGE("Failed to register cloned buffer");
return nullptr;
}
diff --git a/services/vr/vr_window_manager/hwc_callback.cpp b/services/vr/vr_window_manager/hwc_callback.cpp
index 19b220b..43f5042 100644
--- a/services/vr/vr_window_manager/hwc_callback.cpp
+++ b/services/vr/vr_window_manager/hwc_callback.cpp
@@ -38,26 +38,29 @@
HwcCallback::~HwcCallback() {
}
-base::unique_fd HwcCallback::OnNewFrame(const ComposerView::Frame& display_frame) {
- auto& frame = display_frame.layers;
- std::vector<HwcLayer> hwc_frame(frame.size());
-
- for (size_t i = 0; i < frame.size(); ++i) {
+binder::Status HwcCallback::onNewFrame(
+ const ParcelableComposerFrame& parcelable_frame,
+ ParcelableUniqueFd* fence) {
+ ComposerView::Frame frame = parcelable_frame.frame();
+ std::vector<HwcLayer> hwc_frame(frame.layers.size());
+ for (size_t i = 0; i < frame.layers.size(); ++i) {
+ const ComposerView::ComposerLayer& layer = frame.layers[i];
hwc_frame[i] = HwcLayer{
- .fence = frame[i].fence,
- .buffer = frame[i].buffer,
- .crop = frame[i].crop,
- .display_frame = frame[i].display_frame,
- .blending = static_cast<int32_t>(frame[i].blend_mode),
- .appid = frame[i].app_id,
- .type = static_cast<HwcLayer::LayerType>(frame[i].type),
- .alpha = frame[i].alpha,
+ .fence = layer.fence,
+ .buffer = layer.buffer,
+ .crop = layer.crop,
+ .display_frame = layer.display_frame,
+ .blending = static_cast<int32_t>(layer.blend_mode),
+ .appid = layer.app_id,
+ .type = static_cast<HwcLayer::LayerType>(layer.type),
+ .alpha = layer.alpha,
};
}
- return client_->OnFrame(std::make_unique<Frame>(
- std::move(hwc_frame), display_frame.display_id, display_frame.removed,
- display_frame.display_width, display_frame.display_height));
+ fence->set_fence(client_->OnFrame(std::make_unique<Frame>(
+ std::move(hwc_frame), frame.display_id, frame.removed,
+ frame.display_width, frame.display_height)));
+ return binder::Status::ok();
}
HwcCallback::Frame::Frame(std::vector<HwcLayer>&& layers, uint32_t display_id,
diff --git a/services/vr/vr_window_manager/hwc_callback.h b/services/vr/vr_window_manager/hwc_callback.h
index c0d965a..f1f91a1 100644
--- a/services/vr/vr_window_manager/hwc_callback.h
+++ b/services/vr/vr_window_manager/hwc_callback.h
@@ -1,14 +1,16 @@
#ifndef VR_WINDOW_MANAGER_HWC_CALLBACK_H_
#define VR_WINDOW_MANAGER_HWC_CALLBACK_H_
+#include <android/dvr/BnVrComposerCallback.h>
+#include <android-base/unique_fd.h>
+
#include <deque>
#include <functional>
#include <mutex>
#include <vector>
-#include <android-base/unique_fd.h>
-#include <impl/vr_composer_view.h>
-#include <impl/vr_hwc.h>
+#include "impl/vr_composer_view.h"
+#include "impl/vr_hwc.h"
namespace android {
@@ -20,7 +22,7 @@
using Recti = ComposerView::ComposerLayer::Recti;
using Rectf = ComposerView::ComposerLayer::Rectf;
-class HwcCallback : public VrComposerView::Callback {
+class HwcCallback : public BnVrComposerCallback {
public:
struct HwcLayer {
enum LayerType : uint32_t {
@@ -110,7 +112,8 @@
~HwcCallback() override;
private:
- base::unique_fd OnNewFrame(const ComposerView::Frame& frame) override;
+ binder::Status onNewFrame(const ParcelableComposerFrame& frame,
+ ParcelableUniqueFd* fence) override;
Client *client_;
diff --git a/services/vr/vr_window_manager/surface_flinger_view.cpp b/services/vr/vr_window_manager/surface_flinger_view.cpp
index c0ee1fc..aef23a1 100644
--- a/services/vr/vr_window_manager/surface_flinger_view.cpp
+++ b/services/vr/vr_window_manager/surface_flinger_view.cpp
@@ -1,5 +1,7 @@
#include "surface_flinger_view.h"
+#include <android/dvr/IVrComposer.h>
+#include <binder/IServiceManager.h>
#include <impl/vr_composer_view.h>
#include <private/dvr/native_buffer.h>
@@ -14,22 +16,20 @@
SurfaceFlingerView::~SurfaceFlingerView() {}
bool SurfaceFlingerView::Initialize(HwcCallback::Client *client) {
- const char vr_hwcomposer_name[] = "vr";
- vr_hwcomposer_ = HIDL_FETCH_IComposer(vr_hwcomposer_name);
- if (!vr_hwcomposer_.get()) {
- ALOGE("Failed to get vr_hwcomposer");
+ sp<IServiceManager> sm(defaultServiceManager());
+ vr_composer_ = interface_cast<IVrComposer>(
+ sm->getService(IVrComposer::SERVICE_NAME()));
+
+ String8 service_name(IVrComposer::SERVICE_NAME().string());
+ if (!vr_composer_.get()) {
+ ALOGE("Faild to connect to %s", service_name.c_str());
return false;
}
- if (vr_hwcomposer_->isRemote()) {
- ALOGE("vr_hwcomposer service is remote");
- return false;
- }
-
- const android::status_t vr_hwcomposer_status =
- vr_hwcomposer_->registerAsService(vr_hwcomposer_name);
- if (vr_hwcomposer_status != OK) {
- ALOGE("Failed to register vr_hwcomposer service");
+ composer_callback_ = new HwcCallback(client);
+ binder::Status status = vr_composer_->registerObserver(composer_callback_);
+ if (!status.isOk()) {
+ ALOGE("Failed to register observer with %s", service_name.c_str());
return false;
}
diff --git a/services/vr/vr_window_manager/surface_flinger_view.h b/services/vr/vr_window_manager/surface_flinger_view.h
index 3ea2b21..1bea38d 100644
--- a/services/vr/vr_window_manager/surface_flinger_view.h
+++ b/services/vr/vr_window_manager/surface_flinger_view.h
@@ -3,14 +3,13 @@
#include <memory>
-#include <impl/vr_composer_view.h>
-
#include "hwc_callback.h"
namespace android {
namespace dvr {
class IDisplay;
+class IVrComposer;
class Texture;
struct TextureLayer {
@@ -34,8 +33,8 @@
bool skip_first_layer) const;
private:
- sp<IComposer> vr_hwcomposer_;
- std::unique_ptr<VrComposerView> vr_composer_view_;
+ sp<IVrComposer> vr_composer_;
+ sp<HwcCallback> composer_callback_;
SurfaceFlingerView(const SurfaceFlingerView&) = delete;
void operator=(const SurfaceFlingerView&) = delete;
diff --git a/vulkan/libvulkan/swapchain.cpp b/vulkan/libvulkan/swapchain.cpp
index 2fee8a5..3b785e6 100644
--- a/vulkan/libvulkan/swapchain.cpp
+++ b/vulkan/libvulkan/swapchain.cpp
@@ -981,25 +981,9 @@
int gralloc_usage = 0;
if (dispatch.GetSwapchainGrallocUsage2ANDROID) {
uint64_t consumer_usage, producer_usage;
- if (GetData(device).driver_version == 256587285) {
- // HACK workaround for loader/driver mismatch during transition to
- // vkGetSwapchainGrallocUsage2ANDROID.
- typedef VkResult(VKAPI_PTR *
- PFN_vkGetSwapchainGrallocUsage2ANDROID_HACK)(
- VkDevice device, VkFormat format, VkImageUsageFlags imageUsage,
- uint64_t * grallocConsumerUsage,
- uint64_t * grallocProducerUsage);
- auto get_swapchain_gralloc_usage =
- reinterpret_cast<PFN_vkGetSwapchainGrallocUsage2ANDROID_HACK>(
- dispatch.GetSwapchainGrallocUsage2ANDROID);
- result = get_swapchain_gralloc_usage(
- device, create_info->imageFormat, create_info->imageUsage,
- &consumer_usage, &producer_usage);
- } else {
- result = dispatch.GetSwapchainGrallocUsage2ANDROID(
- device, create_info->imageFormat, create_info->imageUsage,
- swapchain_image_usage, &consumer_usage, &producer_usage);
- }
+ result = dispatch.GetSwapchainGrallocUsage2ANDROID(
+ device, create_info->imageFormat, create_info->imageUsage,
+ swapchain_image_usage, &consumer_usage, &producer_usage);
if (result != VK_SUCCESS) {
ALOGE("vkGetSwapchainGrallocUsage2ANDROID failed: %d", result);
return VK_ERROR_SURFACE_LOST_KHR;