summaryrefslogtreecommitdiff
path: root/devices
diff options
context:
space:
mode:
authorEmilian Peev <epeev@google.com>2020-05-11 14:17:18 -0700
committerEmilian Peev <epeev@google.com>2020-05-11 17:37:56 -0700
commitb063278f31edc8b54d9921f394f454a191471181 (patch)
treeae847855b61e31b87c470f0148917902003149b6 /devices
parent5d6df2d62c24dfb1f2d4cc121fbf2cc3d683a37d (diff)
downloadcamera-b063278f31edc8b54d9921f394f454a191471181.tar.gz
EmulatedCamera: Pass dedicated sensor handler to sensor manager
Passing a direct 'EmulatedScene' reference to sensor manager can extend its lifetime and prevent 'EmulatedSensor' from releasing the sensor event queue resources. Avoid this by using a dedicated sensor event handler which will not interfere with the scene lifetime. Additionally correct possible invalid access during sensor start up. Bug: 156290263 Test: Camera CTS Change-Id: I32c178650584bc51468ebc663edc57c0ce6761d2
Diffstat (limited to 'devices')
-rw-r--r--devices/EmulatedCamera/hwl/EmulatedScene.cpp19
-rw-r--r--devices/EmulatedCamera/hwl/EmulatedScene.h19
-rw-r--r--devices/EmulatedCamera/hwl/EmulatedSensor.cpp17
3 files changed, 34 insertions, 21 deletions
diff --git a/devices/EmulatedCamera/hwl/EmulatedScene.cpp b/devices/EmulatedCamera/hwl/EmulatedScene.cpp
index cfd1602..df0c9f2 100644
--- a/devices/EmulatedCamera/hwl/EmulatedScene.cpp
+++ b/devices/EmulatedCamera/hwl/EmulatedScene.cpp
@@ -137,7 +137,12 @@ void EmulatedScene::Initialize(int sensor_width_px, int sensor_height_px,
}
-Return<void> EmulatedScene::onEvent(const Event &e) {
+Return<void> EmulatedScene::SensorHandler::onEvent(const Event& e) {
+ auto scene = scene_.promote();
+ if (scene.get() == nullptr) {
+ return Void();
+ }
+
if (e.sensorType == SensorType::ACCELEROMETER) {
// Heuristic approach for deducing the screen
// rotation depending on the reported
@@ -149,13 +154,13 @@ Return<void> EmulatedScene::onEvent(const Event &e) {
uint32_t x_accel = e.u.vec3.x;
uint32_t y_accel = e.u.vec3.y;
if (x_accel == earth_accel) {
- screen_rotation_ = 270;
+ scene->screen_rotation_ = 270;
} else if (x_accel == -earth_accel) {
- screen_rotation_ = 90;
+ scene->screen_rotation_ = 90;
} else if (y_accel == -earth_accel) {
- screen_rotation_ = 180;
+ scene->screen_rotation_ = 180;
} else {
- screen_rotation_ = 0;
+ scene->screen_rotation_ = 0;
}
} else {
ALOGE("%s: unexpected event received type: %d", __func__, e.sensorType);
@@ -446,8 +451,8 @@ void EmulatedScene::InitializeSensorQueue() {
}
}});
if (sensor_found) {
- manager->createEventQueue(this,
- [&] (const auto &q, auto result) {
+ manager->createEventQueue(
+ new SensorHandler(this), [&](const auto& q, auto result) {
if (result != Result::OK) {
ALOGE("%s: Cannot create event queue", __func__);
return;
diff --git a/devices/EmulatedCamera/hwl/EmulatedScene.h b/devices/EmulatedCamera/hwl/EmulatedScene.h
index 2eb92fa..e3a5238 100644
--- a/devices/EmulatedCamera/hwl/EmulatedScene.h
+++ b/devices/EmulatedCamera/hwl/EmulatedScene.h
@@ -38,7 +38,7 @@ using ::android::hardware::sensors::V1_0::Event;
using ::android::hardware::Return;
using ::android::hardware::Void;
-class EmulatedScene : public IEventQueueCallback {
+class EmulatedScene : public RefBase {
public:
EmulatedScene(int sensor_width_px, int sensor_height_px,
float sensor_sensitivity, int sensor_orientation,
@@ -86,15 +86,24 @@ class EmulatedScene : public IEventQueueCallback {
// indexed with ColorChannels.
const uint32_t* GetPixelElectronsColumn();
- // IEventQueueCallback interface
- Return<void> onEvent(const Event &e) override;
-
enum ColorChannels { R = 0, Gr, Gb, B, Y, Cb, Cr, NUM_CHANNELS };
static const int kSceneWidth = 20;
static const int kSceneHeight = 20;
private:
+ class SensorHandler : public IEventQueueCallback {
+ public:
+ SensorHandler(wp<EmulatedScene> scene) : scene_(scene) {
+ }
+
+ // IEventQueueCallback interface
+ Return<void> onEvent(const Event& e) override;
+
+ private:
+ wp<EmulatedScene> scene_;
+ };
+
void InitiliazeSceneRotation(bool clock_wise);
void InitializeSensorQueue();
@@ -204,7 +213,7 @@ class EmulatedScene : public IEventQueueCallback {
static const uint8_t kMaterialsFlags[NUM_MATERIALS];
static const uint8_t kScene[];
- };
+};
} // namespace android
diff --git a/devices/EmulatedCamera/hwl/EmulatedSensor.cpp b/devices/EmulatedCamera/hwl/EmulatedSensor.cpp
index 794abd2..4eb6926 100644
--- a/devices/EmulatedCamera/hwl/EmulatedSensor.cpp
+++ b/devices/EmulatedCamera/hwl/EmulatedSensor.cpp
@@ -346,15 +346,16 @@ status_t EmulatedSensor::StartUp(
return BAD_VALUE;
}
- auto device_chars = logical_chars->find(logical_camera_id);
- if (device_chars == logical_chars->end()) {
+ chars_ = std::move(logical_chars);
+ auto device_chars = chars_->find(logical_camera_id);
+ if (device_chars == chars_->end()) {
ALOGE(
"%s: Logical camera id: %u absent from logical camera characteristics!",
__FUNCTION__, logical_camera_id);
return BAD_VALUE;
}
- for (const auto& it : *logical_chars) {
+ for (const auto& it : *chars_) {
if (!AreCharacteristicsSupported(it.second)) {
ALOGE("%s: Sensor characteristics for camera id: %u not supported!",
__FUNCTION__, it.first);
@@ -363,12 +364,10 @@ status_t EmulatedSensor::StartUp(
}
logical_camera_id_ = logical_camera_id;
- chars_ = std::move(logical_chars);
- scene_ = new EmulatedScene(device_chars->second.width,
- device_chars->second.height,
- kElectronsPerLuxSecond,
- device_chars->second.orientation,
- device_chars->second.is_front_facing);
+ scene_ = new EmulatedScene(
+ device_chars->second.width, device_chars->second.height,
+ kElectronsPerLuxSecond, device_chars->second.orientation,
+ device_chars->second.is_front_facing);
jpeg_compressor_ = std::make_unique<JpegCompressor>();
auto res = run(LOG_TAG, ANDROID_PRIORITY_URGENT_DISPLAY);