Merge "[libhwc2on1adapter] Fix blueprint warnings"
diff --git a/cmds/dumpstate/utils.cpp b/cmds/dumpstate/utils.cpp
index 4655d33..3153aa5 100644
--- a/cmds/dumpstate/utils.cpp
+++ b/cmds/dumpstate/utils.cpp
@@ -58,6 +58,8 @@
using android::os::dumpstate::DumpFileToFd;
using android::os::dumpstate::PropertiesHelper;
+// Keep in sync with
+// frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
static const int TRACE_DUMP_TIMEOUT_MS = 10000; // 10 seconds
/* Most simple commands have 10 as timeout, so 5 is a good estimate */
diff --git a/cmds/installd/Android.mk b/cmds/installd/Android.mk
index f567a10..be1a434 100644
--- a/cmds/installd/Android.mk
+++ b/cmds/installd/Android.mk
@@ -23,10 +23,9 @@
LOCAL_CFLAGS += -DART_BASE_ADDRESS_MIN_DELTA=$(LOCAL_LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA)
LOCAL_CFLAGS += -DART_BASE_ADDRESS_MAX_DELTA=$(LOCAL_LIBART_IMG_HOST_MAX_BASE_ADDRESS_DELTA)
-LOCAL_SRC_FILES := otapreopt.cpp InstalldNativeService.cpp globals.cpp utils.cpp dexopt.cpp binder/android/os/IInstalld.aidl
+LOCAL_SRC_FILES := otapreopt.cpp globals.cpp utils.cpp dexopt.cpp
LOCAL_SHARED_LIBRARIES := \
libbase \
- libbinder \
libcutils \
liblog \
liblogwrap \
diff --git a/cmds/installd/dexopt.cpp b/cmds/installd/dexopt.cpp
index 5bb2ce7..f7e8d13 100644
--- a/cmds/installd/dexopt.cpp
+++ b/cmds/installd/dexopt.cpp
@@ -1564,7 +1564,7 @@
ALOGV("DexInv: --- END '%s' (success) ---\n", dex_path);
} else {
ALOGE("DexInv: --- END '%s' --- status=0x%04x, process failed\n", dex_path, res);
- return -1;
+ return res;
}
}
diff --git a/cmds/installd/globals.h b/cmds/installd/globals.h
index 8242eec..c90beec 100644
--- a/cmds/installd/globals.h
+++ b/cmds/installd/globals.h
@@ -20,8 +20,6 @@
#include <inttypes.h>
-#include "InstalldNativeService.h"
-
namespace android {
namespace installd {
diff --git a/cmds/installd/otapreopt.cpp b/cmds/installd/otapreopt.cpp
index c74c65b..82b8cc2 100644
--- a/cmds/installd/otapreopt.cpp
+++ b/cmds/installd/otapreopt.cpp
@@ -36,7 +36,6 @@
#include <log/log.h>
#include <private/android_filesystem_config.h>
-#include "InstalldNativeService.h"
#include "dexopt.h"
#include "file_parsing.h"
#include "globals.h"
diff --git a/data/etc/car_core_hardware.xml b/data/etc/car_core_hardware.xml
index ab89ef5..835504f 100644
--- a/data/etc/car_core_hardware.xml
+++ b/data/etc/car_core_hardware.xml
@@ -23,6 +23,9 @@
devices.
-->
<permissions>
+ <!-- This is Android and fully CTS compatible. Basically this is for CTS tests to use. -->
+ <feature name="android.software.cts" />
+
<feature name="android.hardware.audio.output" />
<feature name="android.hardware.location" />
<feature name="android.hardware.location.network" />
diff --git a/data/etc/handheld_core_hardware.xml b/data/etc/handheld_core_hardware.xml
index ed3db5c..2607d58 100644
--- a/data/etc/handheld_core_hardware.xml
+++ b/data/etc/handheld_core_hardware.xml
@@ -23,6 +23,9 @@
devices.
-->
<permissions>
+ <!-- This is Android and fully CTS compatible. Basically this is for CTS tests to use. -->
+ <feature name="android.software.cts" />
+
<feature name="android.hardware.audio.output" />
<feature name="android.hardware.camera" />
<feature name="android.hardware.location" />
diff --git a/data/etc/tablet_core_hardware.xml b/data/etc/tablet_core_hardware.xml
index 7f545e6..f0ca067 100644
--- a/data/etc/tablet_core_hardware.xml
+++ b/data/etc/tablet_core_hardware.xml
@@ -23,6 +23,9 @@
devices.
-->
<permissions>
+ <!-- This is Android and fully CTS compatible. Basically this is for CTS tests to use. -->
+ <feature name="android.software.cts" />
+
<feature name="android.hardware.audio.output" />
<feature name="android.hardware.location" />
<feature name="android.hardware.location.network" />
diff --git a/data/etc/wearable_core_hardware.xml b/data/etc/wearable_core_hardware.xml
index 84230da..a7955e9 100644
--- a/data/etc/wearable_core_hardware.xml
+++ b/data/etc/wearable_core_hardware.xml
@@ -21,6 +21,9 @@
Wearable devices include watches, glasses, backpacks, and sweaters.
-->
<permissions>
+ <!-- This is Android and fully CTS compatible. Basically this is for CTS tests to use. -->
+ <feature name="android.software.cts" />
+
<feature name="android.hardware.location" />
<!-- devices supporting compass/magnitometer sensor must include
android.hardware.sensor.compass.xml -->
diff --git a/libs/gui/tests/Android.bp b/libs/gui/tests/Android.bp
index 4492a08..3a99147 100644
--- a/libs/gui/tests/Android.bp
+++ b/libs/gui/tests/Android.bp
@@ -8,6 +8,7 @@
clang: true,
srcs: [
+ "BufferItemConsumer_test.cpp",
"BufferQueue_test.cpp",
"CpuConsumer_test.cpp",
"FillBuffer.cpp",
diff --git a/libs/gui/tests/BufferItemConsumer_test.cpp b/libs/gui/tests/BufferItemConsumer_test.cpp
new file mode 100644
index 0000000..d64e530
--- /dev/null
+++ b/libs/gui/tests/BufferItemConsumer_test.cpp
@@ -0,0 +1,206 @@
+/*
+ * 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.
+ */
+
+#define LOG_TAG "BufferItemConsumer_test"
+//#define LOG_NDEBUG 0
+
+#include <gtest/gtest.h>
+#include <gui/BufferItemConsumer.h>
+#include <gui/IProducerListener.h>
+#include <gui/Surface.h>
+
+namespace android {
+
+static constexpr int kWidth = 100;
+static constexpr int kHeight = 100;
+static constexpr int kMaxLockedBuffers = 3;
+static constexpr int kFormat = HAL_PIXEL_FORMAT_RGBA_8888;
+static constexpr int kFrameSleepUs = 30 * 1000;
+
+class BufferItemConsumerTest : public ::testing::Test {
+ protected:
+ struct BufferFreedListener
+ : public BufferItemConsumer::BufferFreedListener {
+ explicit BufferFreedListener(BufferItemConsumerTest* test)
+ : mTest(test) {}
+ void onBufferFreed(const wp<GraphicBuffer>& /* gBuffer */) override {
+ mTest->HandleBufferFreed();
+ }
+ BufferItemConsumerTest* mTest;
+ };
+
+ void SetUp() override {
+ BufferQueue::createBufferQueue(&mProducer, &mConsumer);
+ mBIC =
+ new BufferItemConsumer(mConsumer, kFormat, kMaxLockedBuffers, true);
+ String8 name("BufferItemConsumer_Under_Test");
+ mBIC->setName(name);
+ mBFL = new BufferFreedListener(this);
+ mBIC->setBufferFreedListener(mBFL);
+
+ sp<IProducerListener> producerListener = new DummyProducerListener();
+ IGraphicBufferProducer::QueueBufferOutput bufferOutput;
+ ASSERT_EQ(NO_ERROR,
+ mProducer->connect(producerListener, NATIVE_WINDOW_API_CPU,
+ true, &bufferOutput));
+ ASSERT_EQ(NO_ERROR,
+ mProducer->setMaxDequeuedBufferCount(kMaxLockedBuffers));
+ }
+
+ int GetFreedBufferCount() {
+ std::lock_guard<std::mutex> lock(mMutex);
+ return mFreedBufferCount;
+ }
+
+ void HandleBufferFreed() {
+ std::lock_guard<std::mutex> lock(mMutex);
+ mFreedBufferCount++;
+ ALOGV("HandleBufferFreed, mFreedBufferCount=%d", mFreedBufferCount);
+ }
+
+ void DequeueBuffer(int* outSlot) {
+ ASSERT_NE(outSlot, nullptr);
+
+ int slot;
+ sp<Fence> outFence;
+ status_t ret = mProducer->dequeueBuffer(&slot, &outFence, kWidth,
+ kHeight, 0, 0, nullptr);
+ ASSERT_GE(ret, 0);
+
+ ALOGV("dequeueBuffer: slot=%d", slot);
+ if (ret & IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION) {
+ ret = mProducer->requestBuffer(slot, &mBuffers[slot]);
+ ASSERT_EQ(NO_ERROR, ret);
+ }
+ *outSlot = slot;
+ }
+
+ void QueueBuffer(int slot) {
+ ALOGV("enqueueBuffer: slot=%d", slot);
+ IGraphicBufferProducer::QueueBufferInput bufferInput(
+ 0ULL, true, HAL_DATASPACE_UNKNOWN, Rect::INVALID_RECT,
+ NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, Fence::NO_FENCE);
+ IGraphicBufferProducer::QueueBufferOutput bufferOutput;
+ status_t ret = mProducer->queueBuffer(slot, bufferInput, &bufferOutput);
+ ASSERT_EQ(NO_ERROR, ret);
+ }
+
+ void AcquireBuffer(int* outSlot) {
+ ASSERT_NE(outSlot, nullptr);
+ BufferItem buffer;
+ status_t ret = mBIC->acquireBuffer(&buffer, 0, false);
+ ASSERT_EQ(NO_ERROR, ret);
+
+ ALOGV("acquireBuffer: slot=%d", buffer.mSlot);
+ *outSlot = buffer.mSlot;
+ }
+
+ void ReleaseBuffer(int slot) {
+ ALOGV("releaseBuffer: slot=%d", slot);
+ BufferItem buffer;
+ buffer.mSlot = slot;
+ buffer.mGraphicBuffer = mBuffers[slot];
+ status_t ret = mBIC->releaseBuffer(buffer, Fence::NO_FENCE);
+ ASSERT_EQ(NO_ERROR, ret);
+ }
+
+
+ std::mutex mMutex;
+ int mFreedBufferCount{0};
+
+ sp<BufferItemConsumer> mBIC;
+ sp<BufferFreedListener> mBFL;
+ sp<IGraphicBufferProducer> mProducer;
+ sp<IGraphicBufferConsumer> mConsumer;
+ sp<GraphicBuffer> mBuffers[BufferQueueDefs::NUM_BUFFER_SLOTS];
+};
+
+// Test that detaching buffer from consumer side triggers onBufferFreed.
+TEST_F(BufferItemConsumerTest, TriggerBufferFreed_DetachBufferFromConsumer) {
+ int slot;
+ // Producer: generate a dummy buffer.
+ DequeueBuffer(&slot);
+ QueueBuffer(slot);
+
+ ASSERT_EQ(0, GetFreedBufferCount());
+ // Consumer: acquire the buffer and then detach it.
+ AcquireBuffer(&slot);
+ status_t ret = mBIC->detachBuffer(slot);
+ ASSERT_EQ(NO_ERROR, ret);
+
+ // Sleep to give some time for callbacks to happen.
+ usleep(kFrameSleepUs);
+ ASSERT_EQ(1, GetFreedBufferCount());
+}
+
+// Test that detaching buffer from producer side triggers onBufferFreed.
+TEST_F(BufferItemConsumerTest, TriggerBufferFreed_DetachBufferFromProducer) {
+ int slot;
+ // Let buffer go through the cycle at least once.
+ DequeueBuffer(&slot);
+ QueueBuffer(slot);
+ AcquireBuffer(&slot);
+ ReleaseBuffer(slot);
+
+ ASSERT_EQ(0, GetFreedBufferCount());
+
+ // Producer: generate the buffer again.
+ DequeueBuffer(&slot);
+
+ // Producer: detach the buffer.
+ status_t ret = mProducer->detachBuffer(slot);
+ ASSERT_EQ(NO_ERROR, ret);
+
+ // Sleep to give some time for callbacks to happen.
+ usleep(kFrameSleepUs);
+ ASSERT_EQ(1, GetFreedBufferCount());
+}
+
+// Test that abandoning BufferItemConsumer triggers onBufferFreed.
+TEST_F(BufferItemConsumerTest, TriggerBufferFreed_AbandonBufferItemConsumer) {
+ int slot;
+ // Let buffer go through the cycle at least once.
+ DequeueBuffer(&slot);
+ QueueBuffer(slot);
+ AcquireBuffer(&slot);
+ ReleaseBuffer(slot);
+
+ // Abandon the BufferItemConsumer.
+ mBIC->abandon();
+
+ // Sleep to give some time for callbacks to happen.
+ usleep(kFrameSleepUs);
+ ASSERT_EQ(1, GetFreedBufferCount());
+}
+
+// Test that delete BufferItemConsumer triggers onBufferFreed.
+TEST_F(BufferItemConsumerTest, TriggerBufferFreed_DeleteBufferItemConsumer) {
+ int slot;
+ // Let buffer go through the cycle at least once.
+ DequeueBuffer(&slot);
+ QueueBuffer(slot);
+ AcquireBuffer(&slot);
+ ReleaseBuffer(slot);
+
+ // Delete the BufferItemConsumer.
+ mBIC.clear();
+
+ // Sleep to give some time for callbacks to happen.
+ usleep(kFrameSleepUs);
+ ASSERT_EQ(1, GetFreedBufferCount());
+}
+
+} // namespace android
diff --git a/libs/vr/libbufferhubqueue/Android.bp b/libs/vr/libbufferhubqueue/Android.bp
index b976097..1c8f2c0 100644
--- a/libs/vr/libbufferhubqueue/Android.bp
+++ b/libs/vr/libbufferhubqueue/Android.bp
@@ -42,7 +42,10 @@
cc_library {
name: "libbufferhubqueue",
- cflags = [ "-DLOGTAG=\"libbufferhubqueue\"" ],
+ cflags = [
+ "-DLOGTAG=\"libbufferhubqueue\"",
+ "-DTRACE=0",
+ ],
srcs: sourceFiles,
export_include_dirs: includeFiles,
export_static_lib_headers: staticLibraries,
@@ -50,3 +53,4 @@
shared_libs: sharedLibraries,
}
+subdirs = ["tests"]
diff --git a/libs/vr/libbufferhubqueue/buffer_hub_queue_client.cpp b/libs/vr/libbufferhubqueue/buffer_hub_queue_client.cpp
index a8077b9..bd6511d 100644
--- a/libs/vr/libbufferhubqueue/buffer_hub_queue_client.cpp
+++ b/libs/vr/libbufferhubqueue/buffer_hub_queue_client.cpp
@@ -1,7 +1,5 @@
#include "include/private/dvr/buffer_hub_queue_client.h"
-//#define LOG_NDEBUG 0
-
#include <inttypes.h>
#include <log/log.h>
#include <sys/epoll.h>
@@ -73,7 +71,8 @@
auto return_value = status.take();
- ALOGD("CreateConsumerQueue: meta_size_bytes=%zu", return_value.second);
+ ALOGD_IF(TRACE, "BufferHubQueue::CreateConsumerQueue: meta_size_bytes=%zu",
+ return_value.second);
return ConsumerQueue::Create(std::move(return_value.first),
return_value.second);
}
@@ -85,7 +84,7 @@
int ret = epoll_fd_.Wait(events.data(), events.size(), timeout);
if (ret == 0) {
- ALOGD("Wait on epoll returns nothing before timeout.");
+ ALOGD_IF(TRACE, "Wait on epoll returns nothing before timeout.");
return false;
}
@@ -102,7 +101,7 @@
for (int i = 0; i < num_events; i++) {
int64_t index = static_cast<int64_t>(events[i].data.u64);
- ALOGD("New BufferHubQueue event %d: index=%" PRId64, i, index);
+ ALOGD_IF(TRACE, "New BufferHubQueue event %d: index=%" PRId64, i, index);
if (is_buffer_event_index(index)) {
HandleBufferEvent(static_cast<size_t>(index), events[i]);
@@ -255,7 +254,7 @@
size_t* slot,
void* meta,
LocalHandle* fence) {
- ALOGD("Dequeue: count=%zu, timeout=%d", count(), timeout);
+ ALOGD_IF(TRACE, "Dequeue: count=%zu, timeout=%d", count(), timeout);
if (count() == 0 && !WaitForBuffers(timeout))
return nullptr;
@@ -341,8 +340,9 @@
// We only allocate one buffer at a time.
auto& buffer_handle = buffer_handle_slots[0].first;
size_t buffer_slot = buffer_handle_slots[0].second;
- ALOGD("ProducerQueue::AllocateBuffer, new buffer, channel_handle: %d",
- buffer_handle.value());
+ ALOGD_IF(TRACE,
+ "ProducerQueue::AllocateBuffer, new buffer, channel_handle: %d",
+ buffer_handle.value());
*out_slot = buffer_slot;
return AddBuffer(BufferProducer::Import(std::move(buffer_handle)),
@@ -414,8 +414,9 @@
auto buffer_handle_slots = status.take();
for (auto& buffer_handle_slot : buffer_handle_slots) {
- ALOGD("ConsumerQueue::ImportBuffers, new buffer, buffer_handle: %d",
- buffer_handle_slot.first.value());
+ ALOGD_IF(TRACE,
+ "ConsumerQueue::ImportBuffers, new buffer, buffer_handle: %d",
+ buffer_handle_slot.first.value());
std::unique_ptr<BufferConsumer> buffer_consumer =
BufferConsumer::Import(std::move(buffer_handle_slot.first));
@@ -473,7 +474,7 @@
} else if (ret < 0) {
ALOGE("Failed to import buffers on buffer allocated event.");
}
- ALOGD("Imported %d consumer buffers.", ret);
+ ALOGD_IF(TRACE, "Imported %d consumer buffers.", ret);
return ret;
}
diff --git a/libs/vr/libbufferhubqueue/buffer_hub_queue_consumer.cpp b/libs/vr/libbufferhubqueue/buffer_hub_queue_consumer.cpp
index 02bca09..1ea3994 100644
--- a/libs/vr/libbufferhubqueue/buffer_hub_queue_consumer.cpp
+++ b/libs/vr/libbufferhubqueue/buffer_hub_queue_consumer.cpp
@@ -1,7 +1,5 @@
#include "include/private/dvr/buffer_hub_queue_consumer.h"
-//#define LOG_NDEBUG 0
-
namespace android {
namespace dvr {
diff --git a/libs/vr/libbufferhubqueue/buffer_hub_queue_core.cpp b/libs/vr/libbufferhubqueue/buffer_hub_queue_core.cpp
index b013c85..a108042 100644
--- a/libs/vr/libbufferhubqueue/buffer_hub_queue_core.cpp
+++ b/libs/vr/libbufferhubqueue/buffer_hub_queue_core.cpp
@@ -1,8 +1,5 @@
#include "include/private/dvr/buffer_hub_queue_core.h"
-//#define LOG_NDEBUG 0
-#define LOG_TAG "BufferHubQueueCore"
-
#include <log/log.h>
namespace android {
diff --git a/libs/vr/libbufferhubqueue/buffer_hub_queue_producer.cpp b/libs/vr/libbufferhubqueue/buffer_hub_queue_producer.cpp
index 0deb764..ddf7fd2 100644
--- a/libs/vr/libbufferhubqueue/buffer_hub_queue_producer.cpp
+++ b/libs/vr/libbufferhubqueue/buffer_hub_queue_producer.cpp
@@ -1,7 +1,5 @@
#include "include/private/dvr/buffer_hub_queue_producer.h"
-//#define LOG_NDEBUG 0
-
#include <inttypes.h>
#include <log/log.h>
@@ -14,7 +12,7 @@
status_t BufferHubQueueProducer::requestBuffer(int slot,
sp<GraphicBuffer>* buf) {
- ALOGD("requestBuffer: slot=%d", slot);
+ ALOGD_IF(TRACE, "requestBuffer: slot=%d", slot);
std::unique_lock<std::mutex> lock(core_->mutex_);
@@ -35,8 +33,8 @@
status_t BufferHubQueueProducer::setMaxDequeuedBufferCount(
int max_dequeued_buffers) {
- ALOGD("setMaxDequeuedBufferCount: max_dequeued_buffers=%d",
- max_dequeued_buffers);
+ ALOGD_IF(TRACE, "setMaxDequeuedBufferCount: max_dequeued_buffers=%d",
+ max_dequeued_buffers);
std::unique_lock<std::mutex> lock(core_->mutex_);
@@ -63,8 +61,8 @@
PixelFormat format,
uint32_t usage,
FrameEventHistoryDelta* /* outTimestamps */) {
- ALOGD("dequeueBuffer: w=%u, h=%u, format=%d, usage=%u", width, height, format,
- usage);
+ ALOGD_IF(TRACE, "dequeueBuffer: w=%u, h=%u, format=%d, usage=%u", width,
+ height, format, usage);
status_t ret;
std::unique_lock<std::mutex> lock(core_->mutex_);
@@ -134,7 +132,7 @@
core_->buffers_[slot].mBufferState.freeQueued();
core_->buffers_[slot].mBufferState.dequeue();
- ALOGD("dequeueBuffer: slot=%zu", slot);
+ ALOGD_IF(TRACE, "dequeueBuffer: slot=%zu", slot);
// TODO(jwcai) Handle fence properly. |BufferHub| has full fence support, we
// just need to exopose that through |BufferHubQueue| once we need fence.
@@ -173,7 +171,7 @@
status_t BufferHubQueueProducer::queueBuffer(int slot,
const QueueBufferInput& input,
QueueBufferOutput* /* output */) {
- ALOGD("queueBuffer: slot %d", slot);
+ ALOGD_IF(TRACE, "queueBuffer: slot %d", slot);
int64_t timestamp;
sp<Fence> fence;
@@ -220,7 +218,7 @@
status_t BufferHubQueueProducer::cancelBuffer(int slot,
const sp<Fence>& fence) {
- ALOGD(__FUNCTION__);
+ ALOGD_IF(TRACE, __FUNCTION__);
std::unique_lock<std::mutex> lock(core_->mutex_);
@@ -241,13 +239,13 @@
core_->producer_->Enqueue(buffer_producer, slot);
core_->buffers_[slot].mBufferState.cancel();
core_->buffers_[slot].mFence = fence;
- ALOGD("cancelBuffer: slot %d", slot);
+ ALOGD_IF(TRACE, "cancelBuffer: slot %d", slot);
return NO_ERROR;
}
status_t BufferHubQueueProducer::query(int what, int* out_value) {
- ALOGD(__FUNCTION__);
+ ALOGD_IF(TRACE, __FUNCTION__);
std::unique_lock<std::mutex> lock(core_->mutex_);
@@ -278,7 +276,7 @@
return BAD_VALUE;
}
- ALOGD("query: key=%d, v=%d", what, value);
+ ALOGD_IF(TRACE, "query: key=%d, v=%d", what, value);
*out_value = value;
return NO_ERROR;
}
@@ -288,14 +286,14 @@
bool /* producer_controlled_by_app */, QueueBufferOutput* /* output */) {
// Consumer interaction are actually handled by buffer hub, and we need
// to maintain consumer operations here. Hence |connect| is a NO-OP.
- ALOGD(__FUNCTION__);
+ ALOGD_IF(TRACE, __FUNCTION__);
return NO_ERROR;
}
status_t BufferHubQueueProducer::disconnect(int /* api */, DisconnectMode /* mode */) {
// Consumer interaction are actually handled by buffer hub, and we need
// to maintain consumer operations here. Hence |disconnect| is a NO-OP.
- ALOGD(__FUNCTION__);
+ ALOGD_IF(TRACE, __FUNCTION__);
return NO_ERROR;
}
@@ -327,7 +325,7 @@
status_t BufferHubQueueProducer::setGenerationNumber(
uint32_t generation_number) {
- ALOGD(__FUNCTION__);
+ ALOGD_IF(TRACE, __FUNCTION__);
std::unique_lock<std::mutex> lock(core_->mutex_);
core_->generation_number_ = generation_number;
@@ -354,7 +352,7 @@
}
status_t BufferHubQueueProducer::setDequeueTimeout(nsecs_t timeout) {
- ALOGD(__FUNCTION__);
+ ALOGD_IF(TRACE, __FUNCTION__);
std::unique_lock<std::mutex> lock(core_->mutex_);
core_->dequeue_timeout_ms_ = static_cast<int>(timeout / (1000 * 1000));
@@ -374,7 +372,7 @@
}
status_t BufferHubQueueProducer::getUniqueId(uint64_t* out_id) const {
- ALOGD(__FUNCTION__);
+ ALOGD_IF(TRACE, __FUNCTION__);
*out_id = core_->unique_id_;
return NO_ERROR;
diff --git a/libs/vr/libpdx/thread_local_buffer_tests.cpp b/libs/vr/libpdx/thread_local_buffer_tests.cpp
index c6a7b0b..1747d79 100644
--- a/libs/vr/libpdx/thread_local_buffer_tests.cpp
+++ b/libs/vr/libpdx/thread_local_buffer_tests.cpp
@@ -89,8 +89,9 @@
EXPECT_NE(id1, id2);
}
+// TODO(b/36456321): Fix this and enable it again.
// Tests that thread-local buffers are allocated at the first buffer request.
-TEST(ThreadLocalBufferTest, InitialValue) {
+TEST(ThreadLocalBufferTest, DISABLED_InitialValue) {
struct TypeTagX;
using SendSlotX = ThreadLocalSlot<TypeTagX, kSendBufferIndex>;
diff --git a/services/vr/virtual_touchpad/Android.bp b/services/vr/virtual_touchpad/Android.bp
index ad999b7..c8bc884 100644
--- a/services/vr/virtual_touchpad/Android.bp
+++ b/services/vr/virtual_touchpad/Android.bp
@@ -94,6 +94,7 @@
client_src = [
"VirtualTouchpadClient.cpp",
+ "DvrVirtualTouchpadClient.cpp",
"aidl/android/dvr/VirtualTouchpadService.aidl",
]
diff --git a/services/vr/virtual_touchpad/DvrVirtualTouchpadClient.cpp b/services/vr/virtual_touchpad/DvrVirtualTouchpadClient.cpp
new file mode 100644
index 0000000..eb152ed
--- /dev/null
+++ b/services/vr/virtual_touchpad/DvrVirtualTouchpadClient.cpp
@@ -0,0 +1,45 @@
+#include "VirtualTouchpadClient.h"
+#include "dvr/virtual_touchpad_client.h"
+
+struct DvrVirtualTouchpad {};
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+namespace {
+android::dvr::VirtualTouchpad* FromC(DvrVirtualTouchpad* client) {
+ return reinterpret_cast<android::dvr::VirtualTouchpad*>(client);
+}
+} // namespace
+
+DvrVirtualTouchpad* dvrVirtualTouchpadCreate() {
+ return reinterpret_cast<DvrVirtualTouchpad*>(
+ android::dvr::VirtualTouchpadClient::Create().release());
+}
+
+void dvrVirtualTouchpadDestroy(DvrVirtualTouchpad* client) {
+ delete FromC(client);
+}
+
+int dvrVirtualTouchpadAttach(DvrVirtualTouchpad* client) {
+ return FromC(client)->Attach();
+}
+
+int dvrVirtualTouchpadDetach(DvrVirtualTouchpad* client) {
+ return FromC(client)->Detach();
+}
+
+int dvrVirtualTouchpadTouch(DvrVirtualTouchpad* client, int touchpad, float x,
+ float y, float pressure) {
+ return FromC(client)->Touch(touchpad, x, y, pressure);
+}
+
+int dvrVirtualTouchpadButtonState(DvrVirtualTouchpad* client, int touchpad,
+ int buttons) {
+ return FromC(client)->ButtonState(touchpad, buttons);
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/services/vr/virtual_touchpad/VirtualTouchpadClient.cpp b/services/vr/virtual_touchpad/VirtualTouchpadClient.cpp
index 782b19c..c7c8184 100644
--- a/services/vr/virtual_touchpad/VirtualTouchpadClient.cpp
+++ b/services/vr/virtual_touchpad/VirtualTouchpadClient.cpp
@@ -72,8 +72,8 @@
} // anonymous namespace
-sp<VirtualTouchpad> VirtualTouchpadClient::Create() {
- return new VirtualTouchpadClientImpl();
+std::unique_ptr<VirtualTouchpad> VirtualTouchpadClient::Create() {
+ return std::unique_ptr<VirtualTouchpad>(new VirtualTouchpadClientImpl());
}
} // namespace dvr
diff --git a/services/vr/virtual_touchpad/VirtualTouchpadEvdev.cpp b/services/vr/virtual_touchpad/VirtualTouchpadEvdev.cpp
index 92193d3..ee09d48 100644
--- a/services/vr/virtual_touchpad/VirtualTouchpadEvdev.cpp
+++ b/services/vr/virtual_touchpad/VirtualTouchpadEvdev.cpp
@@ -30,10 +30,10 @@
} // anonymous namespace
-sp<VirtualTouchpad> VirtualTouchpadEvdev::Create() {
- VirtualTouchpadEvdev* const touchpad = new VirtualTouchpadEvdev();
+std::unique_ptr<VirtualTouchpad> VirtualTouchpadEvdev::Create() {
+ std::unique_ptr<VirtualTouchpadEvdev> touchpad(new VirtualTouchpadEvdev());
touchpad->Reset();
- return sp<VirtualTouchpad>(touchpad);
+ return touchpad;
}
void VirtualTouchpadEvdev::Reset() {
diff --git a/services/vr/virtual_touchpad/VirtualTouchpadEvdev.h b/services/vr/virtual_touchpad/VirtualTouchpadEvdev.h
index dbaca9a..2fb8ff3 100644
--- a/services/vr/virtual_touchpad/VirtualTouchpadEvdev.h
+++ b/services/vr/virtual_touchpad/VirtualTouchpadEvdev.h
@@ -1,8 +1,6 @@
#ifndef ANDROID_DVR_VIRTUAL_TOUCHPAD_EVDEV_H
#define ANDROID_DVR_VIRTUAL_TOUCHPAD_EVDEV_H
-#include <memory>
-
#include "EvdevInjector.h"
#include "VirtualTouchpad.h"
@@ -15,7 +13,8 @@
//
class VirtualTouchpadEvdev : public VirtualTouchpad {
public:
- static sp<VirtualTouchpad> Create();
+ static std::unique_ptr<VirtualTouchpad> Create();
+ ~VirtualTouchpadEvdev() override {}
// VirtualTouchpad implementation:
status_t Attach() override;
@@ -28,7 +27,6 @@
static constexpr int kTouchpads = 2;
VirtualTouchpadEvdev() {}
- ~VirtualTouchpadEvdev() override {}
void Reset();
// Must be called only between construction (or Detach()) and Attach().
diff --git a/services/vr/virtual_touchpad/VirtualTouchpadService.h b/services/vr/virtual_touchpad/VirtualTouchpadService.h
index 194d787..cf236f9 100644
--- a/services/vr/virtual_touchpad/VirtualTouchpadService.h
+++ b/services/vr/virtual_touchpad/VirtualTouchpadService.h
@@ -13,8 +13,8 @@
//
class VirtualTouchpadService : public BnVirtualTouchpadService {
public:
- VirtualTouchpadService(sp<VirtualTouchpad> touchpad)
- : touchpad_(touchpad), client_pid_(0) {}
+ VirtualTouchpadService(std::unique_ptr<VirtualTouchpad> touchpad)
+ : touchpad_(std::move(touchpad)), client_pid_(0) {}
~VirtualTouchpadService() override;
protected:
@@ -31,7 +31,7 @@
bool CheckPermissions();
bool CheckTouchPermission(pid_t* out_pid);
- sp<VirtualTouchpad> touchpad_;
+ std::unique_ptr<VirtualTouchpad> touchpad_;
// Only one client at a time can use the virtual touchpad.
pid_t client_pid_;
diff --git a/services/vr/virtual_touchpad/include/VirtualTouchpad.h b/services/vr/virtual_touchpad/include/VirtualTouchpad.h
index b1ee700..da3a0b7 100644
--- a/services/vr/virtual_touchpad/include/VirtualTouchpad.h
+++ b/services/vr/virtual_touchpad/include/VirtualTouchpad.h
@@ -1,31 +1,34 @@
#ifndef ANDROID_DVR_VIRTUAL_TOUCHPAD_INTERFACE_H
#define ANDROID_DVR_VIRTUAL_TOUCHPAD_INTERFACE_H
+#include "dvr/virtual_touchpad_client.h"
+
+#include <memory>
#include <utils/Errors.h>
-#include <utils/RefBase.h>
#include <utils/String8.h>
-#include <utils/StrongPointer.h>
namespace android {
namespace dvr {
// Provides a virtual touchpad for injecting events into the input system.
//
-class VirtualTouchpad : public RefBase {
+class VirtualTouchpad {
public:
enum : int {
- PRIMARY = 0,
- VIRTUAL = 1,
+ PRIMARY = DVR_VIRTUAL_TOUCHPAD_PRIMARY,
+ VIRTUAL = DVR_VIRTUAL_TOUCHPAD_VIRTUAL,
};
+ virtual ~VirtualTouchpad() {}
+
// Create a virtual touchpad.
// Implementations should provide this, and hide their constructors.
// For the user, switching implementations should be as simple as changing
// the class whose |Create()| is called.
// Implementations should be minimial; major resource allocation should
// be performed in Attach().
- static sp<VirtualTouchpad> Create() {
- return sp<VirtualTouchpad>();
+ static std::unique_ptr<VirtualTouchpad> Create() {
+ return nullptr;
}
// Initialize a virtual touchpad.
@@ -63,7 +66,6 @@
protected:
VirtualTouchpad() {}
- ~VirtualTouchpad() override {}
private:
VirtualTouchpad(const VirtualTouchpad&) = delete;
diff --git a/services/vr/virtual_touchpad/include/VirtualTouchpadClient.h b/services/vr/virtual_touchpad/include/VirtualTouchpadClient.h
index 471d9e0..23fb9f8 100644
--- a/services/vr/virtual_touchpad/include/VirtualTouchpadClient.h
+++ b/services/vr/virtual_touchpad/include/VirtualTouchpadClient.h
@@ -12,7 +12,7 @@
class VirtualTouchpadClient : public VirtualTouchpad {
public:
// VirtualTouchpad implementation:
- static sp<VirtualTouchpad> Create();
+ static std::unique_ptr<VirtualTouchpad> Create();
status_t Attach() override;
status_t Detach() override;
status_t Touch(int touchpad, float x, float y, float pressure) override;
diff --git a/services/vr/virtual_touchpad/include/dvr/virtual_touchpad_client.h b/services/vr/virtual_touchpad/include/dvr/virtual_touchpad_client.h
new file mode 100644
index 0000000..08cca1b
--- /dev/null
+++ b/services/vr/virtual_touchpad/include/dvr/virtual_touchpad_client.h
@@ -0,0 +1,71 @@
+#ifndef ANDROID_DVR_VIRTUAL_TOUCHPAD_C_CLIENT_H
+#define ANDROID_DVR_VIRTUAL_TOUCHPAD_C_CLIENT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct DvrVirtualTouchpad DvrVirtualTouchpad;
+
+enum {
+ DVR_VIRTUAL_TOUCHPAD_PRIMARY = 0,
+ DVR_VIRTUAL_TOUCHPAD_VIRTUAL = 1,
+};
+
+// Creates a new virtual touchpad client.
+//
+// @return Pointer to the created virtual touchpad client; nullptr on failure.
+//
+DvrVirtualTouchpad* dvrVirtualTouchpadCreate();
+
+// Destroys a virtual touchpad client.
+//
+// @param client Pointer to the virtual touchpad client to be destroyed.
+//
+void dvrVirtualTouchpadDestroy(DvrVirtualTouchpad* client);
+
+// Initialize the virtual touchpad.
+//
+// In the current server implementation, attachment creates and configures
+// the kernel virtual touchpad device(s). A single client may be attached
+// and detached repeatedly, e.g. on entering and leaving VR mode.
+//
+// @param client Pointer to the virtual touchpad client to be attached.
+// @return Zero on success, status_t-style error code on failure.
+//
+int dvrVirtualTouchpadAttach(DvrVirtualTouchpad* client);
+
+// Shut down the virtual touchpad.
+//
+// @param client Pointer to the virtual touchpad client to be detached.
+// @return Zero on success, status_t-style error code on failure.
+//
+int dvrVirtualTouchpadDetach(DvrVirtualTouchpad* client);
+
+// Generate a simulated touch event.
+//
+// @param client Pointer to the virtual touchpad client.
+// @param touchpad Selects touchpad.
+// @param x Horizontal touch position.
+// @param y Vertical touch position.
+// @param pressure Touch pressure; use 0.0 for no touch (lift or hover).
+// @return Zero on success, status_t-style error code on failure.
+//
+int dvrVirtualTouchpadTouch(DvrVirtualTouchpad* client, int touchpad, float x,
+ float y, float pressure);
+
+// Generate a simulated touchpad button state event.
+//
+// @param client Pointer to the virtual touchpad client.
+// @param touchpad Selects touchpad.
+// @param buttons A union of MotionEvent BUTTON_* values.
+// @return Zero on success, status_t-style error code on failure.
+//
+int dvrVirtualTouchpadButtonState(DvrVirtualTouchpad* client, int touchpad,
+ int buttons);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // ANDROID_DVR_VIRTUAL_TOUCHPAD_CLIENT_H
diff --git a/services/vr/virtual_touchpad/main.cpp b/services/vr/virtual_touchpad/main.cpp
index e73f8b9..68f1d70 100644
--- a/services/vr/virtual_touchpad/main.cpp
+++ b/services/vr/virtual_touchpad/main.cpp
@@ -9,7 +9,7 @@
int main() {
ALOGI("Starting");
android::dvr::VirtualTouchpadService touchpad_service(
- android::dvr::VirtualTouchpadEvdev::Create());
+ std::move(android::dvr::VirtualTouchpadEvdev::Create()));
signal(SIGPIPE, SIG_IGN);
android::sp<android::ProcessState> ps(android::ProcessState::self());
diff --git a/services/vr/virtual_touchpad/tests/VirtualTouchpad_test.cpp b/services/vr/virtual_touchpad/tests/VirtualTouchpad_test.cpp
index bc34850..24cfdf8 100644
--- a/services/vr/virtual_touchpad/tests/VirtualTouchpad_test.cpp
+++ b/services/vr/virtual_touchpad/tests/VirtualTouchpad_test.cpp
@@ -95,7 +95,9 @@
class VirtualTouchpadForTesting : public VirtualTouchpadEvdev {
public:
- static sp<VirtualTouchpad> Create() { return sp<VirtualTouchpad>(New()); }
+ static std::unique_ptr<VirtualTouchpad> Create() {
+ return std::unique_ptr<VirtualTouchpad>(New());
+ }
static VirtualTouchpadForTesting* New() {
VirtualTouchpadForTesting* const touchpad = new VirtualTouchpadForTesting();
touchpad->Reset();
@@ -124,7 +126,8 @@
class VirtualTouchpadTest : public testing::Test {};
TEST_F(VirtualTouchpadTest, Goodness) {
- sp<VirtualTouchpadForTesting> touchpad(VirtualTouchpadForTesting::New());
+ std::unique_ptr<VirtualTouchpadForTesting> touchpad(
+ VirtualTouchpadForTesting::New());
UInputRecorder expect;
status_t touch_status = touchpad->Attach();
@@ -284,7 +287,8 @@
}
TEST_F(VirtualTouchpadTest, Badness) {
- sp<VirtualTouchpadForTesting> touchpad(VirtualTouchpadForTesting::New());
+ std::unique_ptr<VirtualTouchpadForTesting> touchpad(
+ VirtualTouchpadForTesting::New());
UInputRecorder expect;
UInputRecorder& record = touchpad->injector[VirtualTouchpad::PRIMARY].record;
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 60ca818..684d15b 100644
--- a/services/vr/vr_window_manager/composer/impl/vr_hwc.cpp
+++ b/services/vr/vr_window_manager/composer/impl/vr_hwc.cpp
@@ -240,12 +240,14 @@
}
}
-uint32_t VrHwc::getMaxVirtualDisplayCount() { return 0; }
+uint32_t VrHwc::getMaxVirtualDisplayCount() { return 1; }
Error VrHwc::createVirtualDisplay(uint32_t width, uint32_t height,
PixelFormat* format, Display* outDisplay) {
*format = PixelFormat::RGBA_8888;
- *outDisplay = 0;
+ *outDisplay = display_count_;
+ displays_[display_count_].reset(new HwcDisplay());
+ display_count_++;
return Error::NONE;
}
@@ -356,7 +358,11 @@
return Error::BAD_DISPLAY;
}
- *outType = IComposerClient::DisplayType::PHYSICAL;
+ if (display == kDefaultDisplayId)
+ *outType = IComposerClient::DisplayType::PHYSICAL;
+ else
+ *outType = IComposerClient::DisplayType::VIRTUAL;
+
return Error::NONE;
}
@@ -443,8 +449,8 @@
if (!display_ptr)
return Error::BAD_DISPLAY;
- ALOGE("Virtual display support not implemented");
- return Error::UNSUPPORTED;
+ // TODO(dnicoara): Is it necessary to do anything here?
+ return Error::NONE;
}
Error VrHwc::validateDisplay(
diff --git a/services/vr/vr_window_manager/composer/impl/vr_hwc.h b/services/vr/vr_window_manager/composer/impl/vr_hwc.h
index b869d3e..3c76120 100644
--- a/services/vr/vr_window_manager/composer/impl/vr_hwc.h
+++ b/services/vr/vr_window_manager/composer/impl/vr_hwc.h
@@ -248,6 +248,7 @@
std::mutex mutex_;
std::unordered_map<Display, std::unique_ptr<HwcDisplay>> displays_;
+ Display display_count_ = 2;
Observer* observer_ = nullptr;
diff --git a/services/vr/vr_window_manager/shell_view.cpp b/services/vr/vr_window_manager/shell_view.cpp
index 72a2c26..a21e883 100644
--- a/services/vr/vr_window_manager/shell_view.cpp
+++ b/services/vr/vr_window_manager/shell_view.cpp
@@ -5,6 +5,7 @@
#include <android/input.h>
#include <binder/IServiceManager.h>
#include <hardware/hwcomposer2.h>
+#include <inttypes.h>
#include <log/log.h>
#include "controller_mesh.h"
@@ -95,7 +96,8 @@
}
int GetTouchIdForDisplay(uint32_t display) {
- return display == 1 ? VirtualTouchpad::PRIMARY : VirtualTouchpad::VIRTUAL;
+ return display == 1 ? DVR_VIRTUAL_TOUCHPAD_PRIMARY
+ : DVR_VIRTUAL_TOUCHPAD_VIRTUAL;
}
} // namespace
@@ -109,8 +111,9 @@
if (ret)
return ret;
- virtual_touchpad_ = VirtualTouchpadClient::Create();
- const status_t touchpad_status = virtual_touchpad_->Attach();
+ virtual_touchpad_.reset(dvrVirtualTouchpadCreate());
+ const status_t touchpad_status =
+ dvrVirtualTouchpadAttach(virtual_touchpad_.get());
if (touchpad_status != OK) {
ALOGE("Failed to connect to virtual touchpad");
return touchpad_status;
@@ -164,13 +167,11 @@
}
void ShellView::EnableDebug(bool debug) {
- ALOGI("EnableDebug(%d)", (int)debug); // XXX TODO delete
QueueTask(debug ? MainThreadTask::EnableDebugMode
: MainThreadTask::DisableDebugMode);
}
void ShellView::VrMode(bool mode) {
- ALOGI("VrMode(%d)", (int)mode); // XXX TODO delete
QueueTask(mode ? MainThreadTask::EnteringVrMode
: MainThreadTask::ExitingVrMode);
}
@@ -180,6 +181,13 @@
result.appendFormat("initialized = %s\n", initialized_ ? "true" : "false");
result.appendFormat("is_visible = %s\n", is_visible_ ? "true" : "false");
result.appendFormat("debug_mode = %s\n\n", debug_mode_ ? "true" : "false");
+
+ result.append("[displays]\n");
+ result.appendFormat("count = %zu\n", displays_.size());
+ for (size_t i = 0; i < displays_.size(); ++i)
+ result.appendFormat(" display_id = %" PRId32 "\n", displays_[i]->id());
+
+ result.append("\n");
}
void ShellView::OnDrawFrame() {
@@ -419,7 +427,7 @@
}
void ShellView::Touch() {
- if (!virtual_touchpad_.get()) {
+ if (!virtual_touchpad_) {
ALOGE("missing virtual touchpad");
return;
}
@@ -431,8 +439,8 @@
// Device is portrait, but in landscape when in VR.
// Rotate touch input appropriately.
- const android::status_t status = virtual_touchpad_->Touch(
- active_display_->touchpad_id(),
+ const android::status_t status = dvrVirtualTouchpadTouch(
+ virtual_touchpad_.get(), active_display_->touchpad_id(),
1.0f - hit_location.y() / size_.y(), hit_location.x() / size_.x(),
is_touching_ ? 1.0f : 0.0f);
if (status != OK) {
@@ -453,7 +461,7 @@
return true;
}
touchpad_buttons_ = buttons;
- if (!virtual_touchpad_.get()) {
+ if (!virtual_touchpad_) {
ALOGE("missing virtual touchpad");
return false;
}
@@ -461,8 +469,9 @@
if (!active_display_)
return true;
- const android::status_t status = virtual_touchpad_->ButtonState(
- active_display_->touchpad_id(), touchpad_buttons_);
+ const android::status_t status = dvrVirtualTouchpadButtonState(
+ virtual_touchpad_.get(), active_display_->touchpad_id(),
+ touchpad_buttons_);
if (status != OK) {
ALOGE("touchpad button failed: %d %d", touchpad_buttons_, status);
}
diff --git a/services/vr/vr_window_manager/shell_view.h b/services/vr/vr_window_manager/shell_view.h
index c10bd27..856c8b8 100644
--- a/services/vr/vr_window_manager/shell_view.h
+++ b/services/vr/vr_window_manager/shell_view.h
@@ -1,12 +1,12 @@
#ifndef VR_WINDOW_MANAGER_SHELL_VIEW_H_
#define VR_WINDOW_MANAGER_SHELL_VIEW_H_
+#include <dvr/virtual_touchpad_client.h>
#include <private/dvr/graphics/mesh.h>
#include <private/dvr/graphics/shader_program.h>
#include <deque>
-#include "VirtualTouchpadClient.h"
#include "application.h"
#include "display_view.h"
#include "reticle.h"
@@ -53,7 +53,6 @@
DisplayView* FindActiveDisplay(const vec3& position, const quat& quaternion,
vec3* hit_location);
-
// HwcCallback::Client:
base::unique_fd OnFrame(std::unique_ptr<HwcCallback::Frame> frame) override;
DisplayView* FindOrCreateDisplay(uint32_t id);
@@ -64,7 +63,15 @@
std::unique_ptr<SurfaceFlingerView> surface_flinger_view_;
std::unique_ptr<Reticle> reticle_;
- sp<VirtualTouchpad> virtual_touchpad_;
+
+ struct DvrVirtualTouchpadDeleter {
+ void operator()(DvrVirtualTouchpad* p) {
+ dvrVirtualTouchpadDetach(p);
+ dvrVirtualTouchpadDestroy(p);
+ }
+ };
+ std::unique_ptr<DvrVirtualTouchpad, DvrVirtualTouchpadDeleter>
+ virtual_touchpad_;
std::unique_ptr<Mesh<vec3, vec3, vec2>> controller_mesh_;