Merge "cuttlefish: gralloc: fix -Wreorder-init-list"
diff --git a/common/libs/auto_resources/auto_resources.cpp b/common/libs/auto_resources/auto_resources.cpp
index 3357b7e..a57c968 100644
--- a/common/libs/auto_resources/auto_resources.cpp
+++ b/common/libs/auto_resources/auto_resources.cpp
@@ -19,29 +19,6 @@
#include <stdlib.h>
#include <string.h>
-bool AutoCloseFILE::CopyFrom(const AutoCloseFILE& in) {
- char buffer[8192];
- while (!in.IsEOF()) {
- size_t num_read = fread(buffer, 1, sizeof(buffer), in);
- if (!num_read) {
- if (in.IsEOF()) {
- return true;
- }
- printf("%s: unable to fread %s:%d (%s)\n",
- __FUNCTION__, __FILE__, __LINE__, strerror(errno));
- return false;
- }
- size_t num_written = fwrite(buffer, 1, num_read, *this);
- if (num_written != num_read) {
- printf("%s: unable to fwrite, %zu != %zu %s:%d (%s)\n",
- __FUNCTION__, num_read, num_written, __FILE__, __LINE__,
- strerror(errno));
- return false;
- }
- }
- return true;
-}
-
AutoFreeBuffer::~AutoFreeBuffer() {
if (data_) free(data_);
}
diff --git a/common/libs/auto_resources/auto_resources.h b/common/libs/auto_resources/auto_resources.h
index 43cb6dc..6dca6a8 100644
--- a/common/libs/auto_resources/auto_resources.h
+++ b/common/libs/auto_resources/auto_resources.h
@@ -32,92 +32,6 @@
#define arraysize(array) (sizeof(ArraySizeHelper(array)))
-// Automatically close a file descriptor
-class AutoCloseFILE {
- public:
- explicit AutoCloseFILE(FILE *f) : f_(f) { }
- virtual ~AutoCloseFILE() {
- if (f_) {
- (void)::fclose(f_);
- f_ = NULL;
- }
- }
-
- operator FILE*() const {
- return f_;
- }
-
- bool CopyFrom(const AutoCloseFILE& in);
-
- bool IsError() const {
- return f_ == NULL;
- }
-
- bool IsEOF() const {
- return IsError() || feof(f_);
- }
-
- bool IsOpen() const {
- return f_ != NULL;
- }
-
- // Close the underlying file descriptor, returning a status to give the caller
- // the chance to act on failure to close.
- // Returns true on success.
- bool close() {
- bool rval = true;
- if (f_) {
- rval = !::fclose(f_);
- f_ = NULL;
- }
- return rval;
- }
-
- private:
- AutoCloseFILE& operator=(const AutoCloseFILE & o);
- explicit AutoCloseFILE(const AutoCloseFILE &);
-
- FILE* f_;
-};
-
-// Automatically close a file descriptor
-class AutoCloseFileDescriptor {
- public:
- explicit AutoCloseFileDescriptor(int fd) : fd_(fd) { }
- virtual ~AutoCloseFileDescriptor() {
- if (fd_ != -1) {
- (void)::close(fd_);
- fd_ = -1;
- }
- }
-
- operator int() const {
- return fd_;
- }
-
- bool IsError() const {
- return fd_ == -1;
- }
-
- // Close the underlying file descriptor, returning a status to give the caller
- // the chance to act on failure to close.
- // Returns true on success.
- bool close() {
- bool rval = true;
- if (fd_ != -1) {
- rval = !::close(fd_);
- fd_ = -1;
- }
- return rval;
- }
-
- private:
- AutoCloseFileDescriptor& operator=(const AutoCloseFileDescriptor & o);
- explicit AutoCloseFileDescriptor(const AutoCloseFileDescriptor &);
-
- int fd_;
-};
-
// In C++11 this is just std::vector<char>, but Android isn't
// there yet.
class AutoFreeBuffer {
@@ -207,17 +121,4 @@
AutoFreeBuffer& operator=(const AutoFreeBuffer&);
explicit AutoFreeBuffer(const AutoFreeBuffer&);
};
-
-class AutoUMask {
- public:
- explicit AutoUMask(mode_t mask) {
- prev_umask = umask(mask);
- }
-
- ~AutoUMask() {
- umask(prev_umask);
- }
- private:
- mode_t prev_umask;
-};
#endif // CUTTLEFISH_COMMON_COMMON_LIBS_AUTO_RESOURCES_AUTO_RESOURCES_H_
diff --git a/common/libs/fs/shared_fd.cpp b/common/libs/fs/shared_fd.cpp
index dde0604..6db27ee 100644
--- a/common/libs/fs/shared_fd.cpp
+++ b/common/libs/fs/shared_fd.cpp
@@ -23,6 +23,7 @@
#include <netinet/in.h>
#include <unistd.h>
#include <algorithm>
+#include <vector>
#include "common/libs/auto_resources/auto_resources.h"
#include "common/libs/glog/logging.h"
@@ -57,8 +58,7 @@
namespace cvd {
bool FileInstance::CopyFrom(FileInstance& in) {
- AutoFreeBuffer buffer;
- buffer.Resize(8192);
+ std::vector<char> buffer(8192);
while (true) {
ssize_t num_read = in.Read(buffer.data(), buffer.size());
if (!num_read) {
@@ -78,8 +78,7 @@
}
bool FileInstance::CopyFrom(FileInstance& in, size_t length) {
- AutoFreeBuffer buffer;
- buffer.Resize(8192);
+ std::vector<char> buffer(8192);
while (length > 0) {
ssize_t num_read = in.Read(buffer.data(), std::min(buffer.size(), length));
length -= num_read;
@@ -95,30 +94,34 @@
}
void FileInstance::Close() {
- AutoFreeBuffer message;
+ std::stringstream message;
if (fd_ == -1) {
errno_ = EBADF;
} else if (close(fd_) == -1) {
errno_ = errno;
if (identity_.size()) {
- message.PrintF("%s: %s failed (%s)", __FUNCTION__, identity_.data(),
- StrError());
- Log(message.data());
+ message << __FUNCTION__ << ": " << identity_ << " failed (" << StrError() << ")";
+ std::string message_str = message.str();
+ Log(message_str.c_str());
}
} else {
if (identity_.size()) {
- message.PrintF("%s: %s succeeded", __FUNCTION__, identity_.data());
- Log(message.data());
+ message << __FUNCTION__ << ": " << identity_ << "succeeded";
+ std::string message_str = message.str();
+ Log(message_str.c_str());
}
}
fd_ = -1;
}
void FileInstance::Identify(const char* identity) {
- identity_.PrintF("fd=%d @%p is %s", fd_, this, identity);
- AutoFreeBuffer message;
- message.PrintF("%s: %s", __FUNCTION__, identity_.data());
- Log(message.data());
+ std::stringstream identity_stream;
+ identity_stream << "fd=" << fd_ << " @" << this << " is " << identity;
+ identity_ = identity_stream.str();
+ std::stringstream message;
+ message << __FUNCTION__ << ": " << identity_;
+ std::string message_str = message.str();
+ Log(message_str.c_str());
}
bool FileInstance::IsSet(fd_set* in) const {
diff --git a/common/libs/fs/shared_fd.h b/common/libs/fs/shared_fd.h
index b811f4a..b64ad09 100644
--- a/common/libs/fs/shared_fd.h
+++ b/common/libs/fs/shared_fd.h
@@ -33,6 +33,7 @@
#include <sys/un.h>
#include <memory>
+#include <sstream>
#include <errno.h>
#include <fcntl.h>
@@ -515,7 +516,9 @@
// Ensure every file descriptor managed by a FileInstance has the CLOEXEC
// flag
TEMP_FAILURE_RETRY(fcntl(fd, F_SETFD, FD_CLOEXEC));
- identity_.PrintF("fd=%d @%p", fd, this);
+ std::stringstream identity;
+ identity << "fd=" << fd << " @" << this;
+ identity_ = identity.str();
}
FileInstance* Accept(struct sockaddr* addr, socklen_t* addrlen) const {
@@ -529,7 +532,7 @@
int fd_;
int errno_;
- AutoFreeBuffer identity_;
+ std::string identity_;
char strerror_buf_[160];
};
diff --git a/common/libs/net/netlink_request.cpp b/common/libs/net/netlink_request.cpp
index 28690a4..ebd84bb 100644
--- a/common/libs/net/netlink_request.cpp
+++ b/common/libs/net/netlink_request.cpp
@@ -35,21 +35,17 @@
}
void* NetlinkRequest::AppendRaw(const void* data, size_t length) {
- void* out = request_.end();
+ size_t original_size = request_.size();
+ request_.resize(original_size + RTA_ALIGN(length), '\0');
+ memcpy(request_.data() + original_size, data, length);
- request_.Append(data, length);
- int pad = RTA_ALIGN(length) - length;
- if (pad > 0) {
- request_.Resize(request_.size() + pad);
- }
-
- return out;
+ return reinterpret_cast<void*>(request_.data() + original_size);
}
void* NetlinkRequest::ReserveRaw(size_t length) {
- void* out = request_.end();
- request_.Resize(request_.size() + RTA_ALIGN(length));
- return out;
+ size_t original_size = request_.size();
+ request_.resize(original_size + RTA_ALIGN(length), '\0');
+ return reinterpret_cast<void*>(request_.data() + original_size);
}
nlattr* NetlinkRequest::AppendTag(
@@ -61,9 +57,9 @@
return attr;
}
-NetlinkRequest::NetlinkRequest(int32_t command, int32_t flags)
- : request_(512),
- header_(Reserve<nlmsghdr>()) {
+NetlinkRequest::NetlinkRequest(int32_t command, int32_t flags) {
+ request_.reserve(512);
+ header_ = Reserve<nlmsghdr>();
flags |= NLM_F_ACK | NLM_F_REQUEST;
header_->nlmsg_flags = flags;
header_->nlmsg_type = command;
@@ -75,7 +71,7 @@
using std::swap;
swap(lists_, other.lists_);
swap(header_, other.header_);
- request_.Swap(other.request_);
+ swap(request_, other.request_);
}
void NetlinkRequest::AddString(uint16_t type, const std::string& value) {
diff --git a/common/libs/net/netlink_request.h b/common/libs/net/netlink_request.h
index e0f8753..5e5b355 100644
--- a/common/libs/net/netlink_request.h
+++ b/common/libs/net/netlink_request.h
@@ -23,8 +23,6 @@
#include <string>
#include <vector>
-#include "common/libs/auto_resources/auto_resources.h"
-
namespace cvd {
// Abstraction of Network link request.
// Used to supply kernel with information about which interface needs to be
@@ -100,7 +98,7 @@
nlattr* AppendTag(uint16_t type, const void* data, uint16_t length);
std::vector<std::pair<nlattr*, int32_t>> lists_;
- AutoFreeBuffer request_;
+ std::vector<char> request_;
nlmsghdr* header_;
NetlinkRequest(const NetlinkRequest&) = delete;
diff --git a/guest/hals/ril/cuttlefish_ril.cpp b/guest/hals/ril/cuttlefish_ril.cpp
index 2053429..cf791b9 100644
--- a/guest/hals/ril/cuttlefish_ril.cpp
+++ b/guest/hals/ril/cuttlefish_ril.cpp
@@ -2229,6 +2229,13 @@
return;
}
+static void request_set_signal_strength_reporting_criteria_1_5(int /*request*/, void* /*data*/,
+ size_t /*datalen*/, RIL_Token t) {
+ ALOGV("request_set_signal_strength_reporting_criteria_1_5 - void");
+ gce_ril_env->OnRequestComplete(t, RIL_E_SUCCESS, NULL, 0);
+ return;
+}
+
static void request_enable_modem(int /*request*/, RIL_Token t) {
ALOGV("Enabling modem - void");
gce_ril_env->OnRequestComplete(t, RIL_E_SUCCESS, NULL, 0);
@@ -2473,6 +2480,9 @@
case RIL_REQUEST_START_NETWORK_SCAN4:
request_start_network_scan4(t);
break;
+ case RIL_REQUEST_SET_SIGNAL_STRENGTH_REPORTING_CRITERIA_1_5:
+ request_set_signal_strength_reporting_criteria_1_5(request, data, datalen, t);
+ break;
case RIL_REQUEST_GET_MODEM_STACK_STATUS:
request_get_modem_stack_status(request, t);
break;
diff --git a/guest/hals/ril/libril/ril.cpp b/guest/hals/ril/libril/ril.cpp
index 3637ac4..ef77ed2 100644
--- a/guest/hals/ril/libril/ril.cpp
+++ b/guest/hals/ril/libril/ril.cpp
@@ -1169,6 +1169,7 @@
case RIL_REQUEST_GET_CARRIER_RESTRICTIONS: return "GET_CARRIER_RESTRICTIONS";
case RIL_REQUEST_GET_CARRIER_RESTRICTIONS_1_4: return "GET_CARRIER_RESTRICTIONS_1_4";
case RIL_REQUEST_SET_CARRIER_INFO_IMSI_ENCRYPTION: return "SET_CARRIER_INFO_IMSI_ENCRYPTION";
+ case RIL_REQUEST_SET_SIGNAL_STRENGTH_REPORTING_CRITERIA_1_5: return "SET_SIGNAL_STRENGTH_REPORTING_CRITERIA_1_5";
case RIL_RESPONSE_ACKNOWLEDGEMENT: return "RESPONSE_ACKNOWLEDGEMENT";
case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
diff --git a/guest/hals/ril/libril/ril.h b/guest/hals/ril/libril/ril.h
index 9b1b0ff..caf6939 100644
--- a/guest/hals/ril/libril/ril.h
+++ b/guest/hals/ril/libril/ril.h
@@ -6561,6 +6561,41 @@
*/
#define RIL_REQUEST_GET_CARRIER_RESTRICTIONS_1_4 154
+/**
+ * Sets the signal strength reporting criteria.
+ *
+ * The resulting reporting rules are the AND of all the supplied criteria. For each RAN
+ * The hysteresisDb apply to only the following measured quantities:
+ * -GERAN - RSSI
+ * -CDMA2000 - RSSI
+ * -UTRAN - RSCP
+ * -EUTRAN - RSRP/RSRQ/RSSNR
+ *
+ * The thresholds apply to only the following measured quantities:
+ * -GERAN - RSSI
+ * -CDMA2000 - RSSI
+ * -UTRAN - RSCP
+ * -EUTRAN - RSRP/RSRQ/RSSNR
+ * -NGRAN - SSRSRP/SSRSRQ/SSSINR
+ *
+ * Note: Reporting criteria must be individually set for each RAN. For any unset reporting
+ * criteria, the value is implementation-defined.
+ *
+ * Note: @1.5::SignalThresholdInfo includes fields 'hysteresisDb', 'hysteresisMs',
+ * and 'thresholds'. As this mechanism generally only constrains reports based on one
+ * measured quantity per RAN, if multiple measured quantities must be used to trigger a report
+ * for a given RAN, the only valid field may be hysteresisMs: hysteresisDb and thresholds must
+ * be set to zero and length zero respectively. If either hysteresisDb or thresholds is set,
+ * then reports shall only be triggered by the respective measured quantity, subject to the
+ * applied constraints.
+ *
+ * Valid errors returned:
+ * RadioError:NONE
+ * RadioError:INVALID_ARGUMENTS
+ * RadioError:RADIO_NOT_AVAILABLE
+ */
+#define RIL_REQUEST_SET_SIGNAL_STRENGTH_REPORTING_CRITERIA_1_5 155
+
/***********************************************************************/
/**
diff --git a/guest/hals/ril/libril/ril_commands.h b/guest/hals/ril/libril/ril_commands.h
index 9355990..3f45151 100644
--- a/guest/hals/ril/libril/ril_commands.h
+++ b/guest/hals/ril/libril/ril_commands.h
@@ -169,3 +169,4 @@
{RIL_REQUEST_ENABLE_MODEM, radio_1_5::enableModemResponse},
{RIL_REQUEST_SET_CARRIER_RESTRICTIONS_1_4, radio_1_5::setAllowedCarriersResponse4},
{RIL_REQUEST_GET_CARRIER_RESTRICTIONS_1_4, radio_1_5::getAllowedCarriersResponse4},
+ {RIL_REQUEST_SET_SIGNAL_STRENGTH_REPORTING_CRITERIA_1_5, radio_1_5::setSignalStrengthReportingCriteriaResponse_1_5},
diff --git a/guest/hals/ril/libril/ril_service.cpp b/guest/hals/ril/libril/ril_service.cpp
index 6101a2e..9e009a5 100755
--- a/guest/hals/ril/libril/ril_service.cpp
+++ b/guest/hals/ril/libril/ril_service.cpp
@@ -531,6 +531,11 @@
::android::hardware::radio::V1_4::SimLockMultiSimPolicy multiSimPolicy);
Return<void> getAllowedCarriers_1_4(int32_t serial);
Return<void> getSignalStrength_1_4(int32_t serial);
+
+ // Methods from ::android::hardware::radio::V1_5::IRadio follow.
+ Return<void> setSignalStrengthReportingCriteria_1_5(int32_t serial,
+ const ::android::hardware::radio::V1_5::SignalThresholdInfo& signalThresholdInfo,
+ const ::android::hardware::radio::V1_5::AccessNetwork accessNetwork);
};
struct OemHookImpl : public IOemHook {
@@ -3207,6 +3212,16 @@
return Void();
}
+Return<void> RadioImpl_1_5::setSignalStrengthReportingCriteria_1_5(int32_t /* serial */,
+ const ::android::hardware::radio::V1_5::SignalThresholdInfo& /* signalThresholdInfo */,
+ const ::android::hardware::radio::V1_5::AccessNetwork /* accessNetwork */) {
+ // TODO implement
+#if VDBG
+ RLOGE("[%04d]< %s", serial, "Method is not implemented");
+#endif
+ return Void();
+}
+
Return<void> RadioImpl_1_5::setLinkCapacityReportingCriteria(int32_t /* serial */,
int32_t /* hysteresisMs */, int32_t /* hysteresisDlKbps */, int32_t /* hysteresisUlKbps */,
const hidl_vec<int32_t>& /* thresholdsDownlinkKbps */,
@@ -7659,6 +7674,25 @@
return 0;
}
+int radio_1_5::setSignalStrengthReportingCriteriaResponse_1_5(int slotId, int responseType,
+ int serial, RIL_Errno e, void* /* response */,
+ size_t responseLen) {
+#if VDBG
+ RLOGD("%s(): %d", __FUNCTION__, serial);
+#endif
+ RadioResponseInfo responseInfo = {};
+ populateResponseInfo(responseInfo, serial, responseType, e);
+
+ if (radioService[slotId]->mRadioResponseV1_5 == NULL) {
+ RLOGE("%s: radioService[%d]->mRadioResponseV1_5 == NULL", __FUNCTION__, slotId);
+ Return<void> retStatus =
+ radioService[slotId]->mRadioResponseV1_5->setSignalStrengthReportingCriteriaResponse_1_5(
+ responseInfo);
+ radioService[slotId]->checkReturnStatus(retStatus);
+ }
+ return 0;
+}
+
/***************************************************************************************************
* INDICATION FUNCTIONS
* The below function handle unsolicited messages coming from the Radio
diff --git a/guest/hals/ril/libril/ril_service.h b/guest/hals/ril/libril/ril_service.h
index be01d6d..b6ba3e4 100644
--- a/guest/hals/ril/libril/ril_service.h
+++ b/guest/hals/ril/libril/ril_service.h
@@ -778,6 +778,10 @@
void *response,
size_t responselen);
+int setSignalStrengthReportingCriteriaResponse_1_5(int slotId,
+ int responseType, int serial, RIL_Errno e,
+ void *response, size_t responselen);
+
pthread_rwlock_t * getRadioServiceRwlock(int slotId);
void setNitzTimeReceived(int slotId, long timeReceived);
diff --git a/guest/hals/sensors/Android.mk b/guest/hals/sensors/Android.mk
deleted file mode 100644
index e9a1a1a..0000000
--- a/guest/hals/sensors/Android.mk
+++ /dev/null
@@ -1,63 +0,0 @@
-# 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.
-
-LOCAL_PATH := $(call my-dir)
-
-# HAL module implemenation stored in
-# hw/<SENSORS_HARDWARE_MODULE_ID>.<ro.hardware>.so
-include $(CLEAR_VARS)
-
-ifeq (0, $(shell test $(PLATFORM_SDK_VERSION) -ge 21; echo $$?))
-LOCAL_MODULE_RELATIVE_PATH := hw
-else
-LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
-endif
-LOCAL_MULTILIB := first
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_SHARED_LIBRARIES := \
- $(VSOC_STLPORT_LIBS) \
- libcuttlefish_fs \
- cuttlefish_auto_resources \
- liblog \
- libcutils
-
-LOCAL_HEADER_LIBRARIES := \
- libhardware_headers
-
-LOCAL_SRC_FILES := \
- sensors.cpp \
- sensors_hal.cpp \
- vsoc_sensors.cpp \
- vsoc_sensors_message.cpp
-
-LOCAL_CFLAGS := -DLOG_TAG=\"VSoC-Sensors\" \
- $(VSOC_VERSION_CFLAGS) \
- -std=c++17 \
- -Werror -Wall -Wno-missing-field-initializers -Wno-unused-parameter
-
-LOCAL_C_INCLUDES := \
- $(VSOC_STLPORT_INCLUDES) \
- device/google/cuttlefish_common \
- system/extras
-
-LOCAL_STATIC_LIBRARIES := \
- libcutils \
- libcuttlefish_remoter_framework \
- $(VSOC_STLPORT_STATIC_LIBS)
-
-LOCAL_MODULE := sensors.cutf
-LOCAL_VENDOR_MODULE := true
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/guest/hals/sensors/sensors.cpp b/guest/hals/sensors/sensors.cpp
deleted file mode 100644
index 951461d..0000000
--- a/guest/hals/sensors/sensors.cpp
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * 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 "guest/hals/sensors/vsoc_sensors.h"
-
-#include <limits>
-
-#include "guest/hals/sensors/sensors.h"
-
-namespace cvd {
-namespace {
-const cvd::time::Milliseconds kDefaultSamplingRate(200);
-
-timespec infinity() {
- timespec ts;
- ts.tv_sec = std::numeric_limits<time_t>::max();
- ts.tv_nsec = 0;
- return ts;
-}
-} // namespace
-
-const cvd::time::MonotonicTimePoint SensorState::kInfinity =
- cvd::time::MonotonicTimePoint(infinity());
-
-SensorState::SensorState(SensorInfo info)
- : enabled_(false),
- event_(),
- deadline_(kInfinity),
- sampling_period_(kDefaultSamplingRate) {
- event_.sensor = info.handle;
- event_.type = info.type;
-}
-
-SensorInfo::SensorInfo(const char* name, const char* vendor, int version,
- int handle, int type, float max_range, float resolution,
- float power, int32_t min_delay,
- uint32_t fifo_reserved_event_count,
- uint32_t fifo_max_event_count, const char* string_type,
- const char* required_permission, int32_t max_delay,
- uint32_t reporting_mode) {
- this->name = name;
- this->vendor = vendor;
- this->version = version;
- this->handle = handle;
- this->type = type;
- this->maxRange = max_range;
- this->resolution = resolution;
- this->power = power;
- this->minDelay = min_delay;
- this->fifoReservedEventCount = fifo_reserved_event_count;
- this->fifoMaxEventCount = fifo_max_event_count;
- this->stringType = string_type;
- this->requiredPermission = required_permission;
- this->maxDelay = max_delay;
- this->flags = reporting_mode;
-}
-
-namespace sc = sensors_constants;
-
-SensorInfo AccelerometerSensor() {
- uint32_t flags = sc::kAccelerometerReportingMode |
- (sc::kAccelerometerIsWakeup ? SENSOR_FLAG_WAKE_UP : 0);
-
- return SensorInfo(sc::kAccelerometerName, sc::kVendor, sc::kVersion,
- sc::kAccelerometerHandle, SENSOR_TYPE_ACCELEROMETER,
- sc::kAccelerometerMaxRange, sc::kAccelerometerResolution,
- sc::kAccelerometerPower, sc::kAccelerometerMinDelay,
- sc::kFifoReservedEventCount, sc::kFifoMaxEventCount,
- sc::kAccelerometerStringType, sc::kRequiredPermission,
- sc::kMaxDelay, flags);
-}
-
-SensorInfo GyroscopeSensor() {
- uint32_t flags = sc::kGyroscopeReportingMode |
- (sc::kGyroscopeIsWakeup ? SENSOR_FLAG_WAKE_UP : 0);
-
- return SensorInfo(
- sc::kGyroscopeName, sc::kVendor, sc::kVersion, sc::kGyroscopeHandle,
- SENSOR_TYPE_GYROSCOPE, sc::kGyroscopeMaxRange, sc::kGyroscopeResolution,
- sc::kGyroscopePower, sc::kGyroscopeMinDelay, sc::kFifoReservedEventCount,
- sc::kFifoMaxEventCount, sc::kGyroscopeStringType, sc::kRequiredPermission,
- sc::kMaxDelay, flags);
-}
-
-SensorInfo LightSensor() {
- uint32_t flags = sc::kLightReportingMode |
- (sc::kLightIsWakeup ? SENSOR_FLAG_WAKE_UP : 0);
-
- return SensorInfo(sc::kLightName, sc::kVendor, sc::kVersion, sc::kLightHandle,
- SENSOR_TYPE_LIGHT, sc::kLightMaxRange, sc::kLightResolution,
- sc::kLightPower, sc::kLightMinDelay,
- sc::kFifoReservedEventCount, sc::kFifoMaxEventCount,
- sc::kLightStringType, sc::kRequiredPermission,
- sc::kMaxDelay, flags);
-}
-
-SensorInfo MagneticFieldSensor() {
- uint32_t flags = sc::kMagneticFieldReportingMode |
- (sc::kMagneticFieldIsWakeup ? SENSOR_FLAG_WAKE_UP : 0);
-
- return SensorInfo(sc::kMagneticFieldName, sc::kVendor, sc::kVersion,
- sc::kMagneticFieldHandle, SENSOR_TYPE_MAGNETIC_FIELD,
- sc::kMagneticFieldMaxRange, sc::kMagneticFieldResolution,
- sc::kMagneticFieldPower, sc::kMagneticFieldMinDelay,
- sc::kFifoReservedEventCount, sc::kFifoMaxEventCount,
- sc::kMagneticFieldStringType, sc::kRequiredPermission,
- sc::kMaxDelay, flags);
-}
-
-SensorInfo PressureSensor() {
- uint32_t flags = sc::kPressureReportingMode |
- (sc::kPressureIsWakeup ? SENSOR_FLAG_WAKE_UP : 0);
-
- return SensorInfo(
- sc::kPressureName, sc::kVendor, sc::kVersion, sc::kPressureHandle,
- SENSOR_TYPE_PRESSURE, sc::kPressureMaxRange, sc::kPressureResolution,
- sc::kPressurePower, sc::kPressureMinDelay, sc::kFifoReservedEventCount,
- sc::kFifoMaxEventCount, sc::kPressureStringType, sc::kRequiredPermission,
- sc::kMaxDelay, flags);
-}
-
-SensorInfo ProximitySensor() {
- uint32_t flags = sc::kProximityReportingMode |
- (sc::kProximityIsWakeup ? SENSOR_FLAG_WAKE_UP : 0);
-
- return SensorInfo(
- sc::kProximityName, sc::kVendor, sc::kVersion, sc::kProximityHandle,
- SENSOR_TYPE_PROXIMITY, sc::kProximityMaxRange, sc::kProximityResolution,
- sc::kProximityPower, sc::kProximityMinDelay, sc::kFifoReservedEventCount,
- sc::kFifoMaxEventCount, sc::kProximityStringType, sc::kRequiredPermission,
- sc::kMaxDelay, flags);
-}
-
-SensorInfo AmbientTempSensor() {
- uint32_t flags = sc::kAmbientTempReportingMode |
- (sc::kAmbientTempIsWakeup ? SENSOR_FLAG_WAKE_UP : 0);
-
- return SensorInfo(sc::kAmbientTempName, sc::kVendor, sc::kVersion,
- sc::kAmbientTempHandle, SENSOR_TYPE_AMBIENT_TEMPERATURE,
- sc::kAmbientTempMaxRange, sc::kAmbientTempResolution,
- sc::kAmbientTempPower, sc::kAmbientTempMinDelay,
- sc::kFifoReservedEventCount, sc::kFifoMaxEventCount,
- sc::kAmbientTempStringType, sc::kRequiredPermission,
- sc::kMaxDelay, flags);
-}
-
-SensorInfo DeviceTempSensor() {
- uint32_t flags = sc::kDeviceTempReportingMode |
- (sc::kDeviceTempIsWakeup ? SENSOR_FLAG_WAKE_UP : 0);
-
- return SensorInfo(sc::kDeviceTempName, sc::kVendor, sc::kVersion,
- sc::kDeviceTempHandle, SENSOR_TYPE_TEMPERATURE,
- sc::kDeviceTempMaxRange, sc::kDeviceTempResolution,
- sc::kDeviceTempPower, sc::kDeviceTempMinDelay,
- sc::kFifoReservedEventCount, sc::kFifoMaxEventCount,
- sc::kDeviceTempStringType, sc::kRequiredPermission,
- sc::kMaxDelay, flags);
-}
-
-SensorInfo RelativeHumiditySensor() {
- uint32_t flags = sc::kRelativeHumidityReportingMode |
- (sc::kRelativeHumidityIsWakeup ? SENSOR_FLAG_WAKE_UP : 0);
-
- return SensorInfo(sc::kRelativeHumidityName, sc::kVendor, sc::kVersion,
- sc::kRelativeHumidityHandle, SENSOR_TYPE_RELATIVE_HUMIDITY,
- sc::kRelativeHumidityMaxRange,
- sc::kRelativeHumidityResolution, sc::kRelativeHumidityPower,
- sc::kRelativeHumidityMinDelay, sc::kFifoReservedEventCount,
- sc::kFifoMaxEventCount, sc::kRelativeHumidityStringType,
- sc::kRequiredPermission, sc::kMaxDelay,
- flags);
-}
-
-} // namespace cvd
diff --git a/guest/hals/sensors/sensors.h b/guest/hals/sensors/sensors.h
deleted file mode 100644
index 9543e4e..0000000
--- a/guest/hals/sensors/sensors.h
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * 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.
- */
-#pragma once
-
-#include "common/libs/time/monotonic_time.h"
-#include "guest/hals/sensors/sensors_hal.h"
-
-namespace cvd {
-
-// Stores static information about a sensor.
-// Must be completely compatible with sensor_t (i.e. no additional
-// information or virtual functions)
-// so we can cast a list of SensorInfo to a list of sensor_t.
-class SensorInfo : public sensor_t {
- public:
- // Dummy, empty set of sensor information (value-initialized).
- SensorInfo() : sensor_t() {}
-
- private:
- SensorInfo(const char* name, const char* vendor, int version, int handle,
- int type, float max_range, float resolution, float power,
- int32_t min_delay, uint32_t fifo_reserved_event_count,
- uint32_t fifo_max_event_count, const char* string_type,
- const char* required_permission, int32_t max_delay,
- uint32_t reporting_mode);
-
- friend SensorInfo AccelerometerSensor();
- friend SensorInfo GyroscopeSensor();
- friend SensorInfo LightSensor();
- friend SensorInfo MagneticFieldSensor();
- friend SensorInfo PressureSensor();
- friend SensorInfo ProximitySensor();
- friend SensorInfo AmbientTempSensor();
- friend SensorInfo DeviceTempSensor();
- friend SensorInfo RelativeHumiditySensor();
-};
-
-SensorInfo AccelerometerSensor();
-SensorInfo GyroscopeSensor();
-SensorInfo LightSensor();
-SensorInfo MagneticFieldSensor();
-SensorInfo PressureSensor();
-SensorInfo ProximitySensor();
-SensorInfo AmbientTempSensor();
-SensorInfo DeviceTempSensor();
-SensorInfo RelativeHumiditySensor();
-
-// Stores the current state of a sensor.
-class SensorState {
- public:
- SensorState(SensorInfo info);
- virtual ~SensorState() {}
-
- // What this sensor is activated or not.
- bool enabled_;
- // Buffer of incoming events.
- sensors_event_t event_;
- // The deadline at which we should report the next sensor event
- // to the framework in order to meet our frequency constraints.
- // For disabled sensors, should be 'infinity'.
- cvd::time::MonotonicTimePoint deadline_;
- // Delay time between consecutive sensor samples, in ns.
- cvd::time::Nanoseconds sampling_period_;
-
- // Time 'infinity'.
- static const cvd::time::MonotonicTimePoint kInfinity;
-};
-
-namespace sensors_constants {
-// TODO: Verify these numbers.
-// Vendor of the hardware part.
-const char kVendor[] = "Google";
-// Version of the hardware part + driver. The value of this field
-// must increase when the driver is updated in a way that
-// changes the output of the sensor.
-const int kVersion = VSOC_SENSOR_DEVICE_VERSION;
-// Number of events reserved for this sensor in batch mode FIFO.
-// If it has its own FIFO, the size of that FIFO.
-const uint32_t kFifoReservedEventCount = 15;
-// Maximum events that can be batched. In a shared FIFO,
-// the size of that FIFO.
-const uint32_t kFifoMaxEventCount = 15;
-// Permission required to use this sensor, or empty string
-// if none required.
-const char kRequiredPermission[] = "";
-// Defined only for continuous mode and on-change sensors.
-// Delay corresponding with lowest frequency supported.
-const int32_t kMaxDelay = 5000000;
-
-// Name of this sensor. Must be unique.
-const char kAccelerometerName[] = "acceleration";
-const char kGyroscopeName[] = "gyroscope";
-const char kLightName[] = "light";
-const char kMagneticFieldName[] = "magnetic_field";
-const char kPressureName[] = "pressure";
-const char kProximityName[] = "proximity";
-const char kAmbientTempName[] = "ambient_temp";
-const char kDeviceTempName[] = "device_temp";
-const char kRelativeHumidityName[] = "relative_humidity";
-
-// Handle that identifies the sensor. This is used as an array index,
-// so must be unique in the range [0, # sensors)
-
-const int kAccelerometerHandle = 0;
-const int kGyroscopeHandle = 1;
-const int kLightHandle = 2;
-const int kMagneticFieldHandle = 3;
-const int kPressureHandle = 4;
-const int kProximityHandle = 5;
-const int kAmbientTempHandle = 6;
-const int kDeviceTempHandle = 7;
-const int kRelativeHumidityHandle = 8;
-
-// For continuous sensors, minimum sample period (in microseconds).
-// On-Change (0), One-shot (-1), and special (0).
-const int32_t kAccelerometerMinDelay = 4444;
-const int32_t kGyroscopeMinDelay = 4444;
-const int32_t kLightMinDelay = 0;
-const int32_t kMagneticFieldMinDelay = 14285;
-const int32_t kPressureMinDelay = 28571;
-const int32_t kProximityMinDelay = 0;
-const int32_t kAmbientTempMinDelay = 4444;
-const int32_t kDeviceTempMinDelay = 4444;
-const int32_t kRelativeHumidityMinDelay = 4444;
-
-// Maximum range of this sensor's value in SI units.
-const float kAccelerometerMaxRange = 39.226593f;
-const float kGyroscopeMaxRange = 8.726639f;
-const float kLightMaxRange = 10000.0f;
-const float kMagneticFieldMaxRange = 4911.9995f;
-const float kPressureMaxRange = 1100.0f;
-const float kProximityMaxRange = 5.0f;
-const float kAmbientTempMaxRange = 80.0f;
-const float kDeviceTempMaxRange = 80.0f;
-const float kRelativeHumidityMaxRange = 100;
-
-// Smallest difference between two values reported by this sensor.
-const float kAccelerometerResolution = 0.45f;
-const float kGyroscopeResolution = 10.0f;
-const float kLightResolution = 10.0f;
-const float kMagneticFieldResolution = 1.0f;
-const float kPressureResolution = 1.0f;
-const float kProximityResolution = 1.0f;
-const float kAmbientTempResolution = 1.0f;
-const float kDeviceTempResolution = 1.0f;
-const float kRelativeHumidityResolution = 1.0f;
-
-// Rough estimate of this sensor's power consumption in mA.
-const float kAccelerometerPower = 0.45f;
-const float kGyroscopePower = 3.6f;
-const float kLightPower = 0.175f;
-const float kMagneticFieldPower = 5.0f;
-const float kPressurePower = 0.004f;
-const float kProximityPower = 12.675f;
-const float kAmbientTempPower = 1.0f;
-const float kDeviceTempPower = 1.0f;
-const float kRelativeHumidityPower = 1.0f;
-
-// Type of this sensor, represented as a string.
-
-const char kAccelerometerStringType[] = SENSOR_STRING_TYPE_ACCELEROMETER;
-const char kGyroscopeStringType[] = SENSOR_STRING_TYPE_GYROSCOPE;
-const char kLightStringType[] = SENSOR_STRING_TYPE_LIGHT;
-const char kMagneticFieldStringType[] = SENSOR_STRING_TYPE_MAGNETIC_FIELD;
-const char kPressureStringType[] = SENSOR_STRING_TYPE_PRESSURE;
-const char kProximityStringType[] = SENSOR_STRING_TYPE_PROXIMITY;
-const char kAmbientTempStringType[] = SENSOR_STRING_TYPE_AMBIENT_TEMPERATURE;
-const char kDeviceTempStringType[] = SENSOR_STRING_TYPE_TEMPERATURE;
-const char kRelativeHumidityStringType[] = SENSOR_STRING_TYPE_RELATIVE_HUMIDITY;
-
-const uint32_t kAccelerometerReportingMode = SENSOR_FLAG_CONTINUOUS_MODE;
-const uint32_t kGyroscopeReportingMode = SENSOR_FLAG_CONTINUOUS_MODE;
-const uint32_t kLightReportingMode = SENSOR_FLAG_ON_CHANGE_MODE;
-const uint32_t kMagneticFieldReportingMode = SENSOR_FLAG_CONTINUOUS_MODE;
-const uint32_t kPressureReportingMode = SENSOR_FLAG_CONTINUOUS_MODE;
-const uint32_t kProximityReportingMode = SENSOR_FLAG_ON_CHANGE_MODE;
-const uint32_t kAmbientTempReportingMode = SENSOR_FLAG_ON_CHANGE_MODE;
-const uint32_t kDeviceTempReportingMode = SENSOR_FLAG_ON_CHANGE_MODE;
-const uint32_t kRelativeHumidityReportingMode = SENSOR_FLAG_ON_CHANGE_MODE;
-
-const bool kAccelerometerIsWakeup = false;
-const bool kGyroscopeIsWakeup = false;
-const bool kLightIsWakeup = false;
-const bool kMagneticFieldIsWakeup = false;
-const bool kPressureIsWakeup = false;
-const bool kProximityIsWakeup = true;
-const bool kAmbientTempIsWakeup = false;
-const bool kDeviceTempIsWakeup = false;
-const bool kRelativeHumidityIsWakeup = false;
-
-} // namespace sensors_constants
-} // namespace cvd
-
diff --git a/guest/hals/sensors/sensors_hal.cpp b/guest/hals/sensors/sensors_hal.cpp
deleted file mode 100644
index c1e2284..0000000
--- a/guest/hals/sensors/sensors_hal.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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 "guest/hals/sensors/sensors_hal.h"
-
-#include "guest/hals/sensors/vsoc_sensors.h"
-
-static hw_module_methods_t hal_module_methods = {
- .open = cvd::GceSensors::Open,
-};
-
-sensors_module_t HAL_MODULE_INFO_SYM = {
- .common = {
- .tag = HARDWARE_MODULE_TAG,
- .module_api_version = 1,
- .hal_api_version = 0,
- .id = SENSORS_HARDWARE_MODULE_ID,
- .name = "Android-GCE SENSORS Module",
- .author = "Google",
- .methods = & hal_module_methods,
- },
- .get_sensors_list = cvd::GceSensors::GetSensorsList,
- .set_operation_mode = cvd::GceSensors::SetOperationMode,
-};
diff --git a/guest/hals/sensors/sensors_hal.h b/guest/hals/sensors/sensors_hal.h
deleted file mode 100644
index 263bf09..0000000
--- a/guest/hals/sensors/sensors_hal.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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.
- */
-#pragma once
-
-#include <log/log.h>
-#include <hardware/hardware.h>
-#include <hardware/sensors.h>
-
-#define VSOC_SENSOR_DEVICE_VERSION SENSORS_DEVICE_API_VERSION_1_4
-
-#define SENSORS_DEBUG 0
-
-#if SENSORS_DEBUG
-# define D(...) ALOGD(__VA_ARGS__)
-#else
-# define D(...) ((void)0)
-#endif
-
diff --git a/guest/hals/sensors/vsoc_sensors.cpp b/guest/hals/sensors/vsoc_sensors.cpp
deleted file mode 100644
index c9388b0..0000000
--- a/guest/hals/sensors/vsoc_sensors.cpp
+++ /dev/null
@@ -1,509 +0,0 @@
-/*
- * 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 <cstdint>
-
-#include <cutils/properties.h>
-#include <cutils/sockets.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/system_properties.h>
-#include <unistd.h>
-
-#include <algorithm>
-
-#include "common/libs/fs/shared_select.h"
-#include "common/libs/threads/thunkers.h"
-#include "guest/hals/sensors/sensors_hal.h"
-#include "guest/hals/sensors/vsoc_sensors.h"
-#include "guest/hals/sensors/vsoc_sensors_message.h"
-#include "guest/libs/remoter/remoter_framework_pkt.h"
-
-using cvd::LockGuard;
-using cvd::Mutex;
-using cvd::time::Milliseconds;
-using cvd::time::MonotonicTimePoint;
-using cvd::time::Nanoseconds;
-
-namespace cvd {
-
-int GceSensors::total_sensor_count_ = -1;
-SensorInfo* GceSensors::sensor_infos_ = NULL;
-const int GceSensors::kInjectedEventWaitPeriods = 3;
-const Nanoseconds GceSensors::kInjectedEventWaitTime =
- Nanoseconds(Milliseconds(20));
-
-GceSensors::GceSensors()
- : sensors_poll_device_1(), deadline_change_(&sensor_state_lock_) {
- if (total_sensor_count_ == -1) {
- RegisterSensors();
- }
-
- // Create a pair of FDs that would be used to control the
- // receiver thread.
- if (control_sender_socket_->IsOpen() || control_receiver_socket_->IsOpen()) {
- ALOGE("%s: Receiver control FDs are opened", __FUNCTION__);
- }
- if (!cvd::SharedFD::Pipe(&control_receiver_socket_,
- &control_sender_socket_)) {
- ALOGE("%s: Unable to create thread control FDs: %d -> %s", __FUNCTION__,
- errno, strerror(errno));
- }
-
- // Create the correct number of holding buffers for this client.
- sensor_states_.resize(total_sensor_count_);
- int i;
- for (i = 0; i < total_sensor_count_; i++) {
- sensor_states_[i] = new SensorState(sensor_infos_[i]);
- }
-}
-
-GceSensors::~GceSensors() {
- int i;
- for (i = 0; i < total_sensor_count_; i++) {
- delete sensor_states_[i];
- }
-}
-
-int GceSensors::GetSensorsList(struct sensors_module_t* /*module*/,
- struct sensor_t const** list) {
- *list = sensor_infos_;
- return total_sensor_count_;
-}
-
-int GceSensors::SetOperationMode(unsigned int /* is_loopback_mode */) {
- return -EINVAL;
-}
-
-int GceSensors::Open(const struct hw_module_t* module, const char* name,
- struct hw_device_t** device) {
- int status = -EINVAL;
-
- if (!strcmp(name, SENSORS_HARDWARE_POLL)) {
- // Create a new GceSensors object and set all the fields/functions
- // to their default values.
- GceSensors* rval = new GceSensors;
-
- rval->common.tag = HARDWARE_DEVICE_TAG;
- rval->common.version = VSOC_SENSOR_DEVICE_VERSION;
- rval->common.module = (struct hw_module_t*)module;
- rval->common.close = cvd::thunk<hw_device_t, &GceSensors::Close>;
-
- rval->poll = cvd::thunk<sensors_poll_device_t, &GceSensors::Poll>;
- rval->activate = cvd::thunk<sensors_poll_device_t, &GceSensors::Activate>;
- rval->setDelay = cvd::thunk<sensors_poll_device_t, &GceSensors::SetDelay>;
-
- rval->batch = cvd::thunk<sensors_poll_device_1, &GceSensors::Batch>;
- rval->flush = cvd::thunk<sensors_poll_device_1, &GceSensors::Flush>;
- rval->inject_sensor_data =
- cvd::thunk<sensors_poll_device_1, &GceSensors::InjectSensorData>;
-
- // Spawn a thread to listen for incoming data from the remoter.
- int err = pthread_create(
- &rval->receiver_thread_, NULL,
- cvd::thunk<void, &GceSensors::Receiver>,
- rval);
- if (err) {
- ALOGE("GceSensors::%s: Unable to start receiver thread (%s)",
- __FUNCTION__, strerror(err));
- }
-
- *device = &rval->common;
- status = 0;
- }
- return status;
-}
-
-int GceSensors::Close() {
- // Make certain the receiver thread wakes up.
- SensorControlMessage msg;
- msg.message_type = THREAD_STOP;
- SendControlMessage(msg);
- pthread_join(receiver_thread_, NULL);
- delete this;
- return 0;
-}
-
-int GceSensors::Activate(int handle, int enabled) {
- if (handle < 0 || handle >= total_sensor_count_) {
- ALOGE("GceSensors::%s: Bad handle %d", __FUNCTION__, handle);
- return -1;
- }
-
- {
- LockGuard<Mutex> guard(sensor_state_lock_);
- // Update the report deadline, if changed.
- if (enabled && !sensor_states_[handle]->enabled_) {
- sensor_states_[handle]->deadline_ =
- MonotonicTimePoint::Now() + sensor_states_[handle]->sampling_period_;
- } else if (!enabled && sensor_states_[handle]->enabled_) {
- sensor_states_[handle]->deadline_ = SensorState::kInfinity;
- }
- sensor_states_[handle]->enabled_ = enabled;
- UpdateDeadline();
- }
-
- D("sensor_activate(): handle %d, enabled %d", handle, enabled);
- if (!UpdateRemoterState(handle)) {
- ALOGE("Failed to notify remoter about new sensor enable/disable.");
- }
- return 0;
-}
-
-int GceSensors::SetDelay(int handle, int64_t sampling_period_ns) {
- if (handle < 0 || handle >= total_sensor_count_) {
- ALOGE("GceSensors::%s: Bad handle %d", __FUNCTION__, handle);
- return -1;
- }
- int64_t min_delay_ns = sensor_infos_[handle].minDelay * 1000;
- if (sampling_period_ns < min_delay_ns) {
- sampling_period_ns = min_delay_ns;
- }
-
- {
- LockGuard<Mutex> guard(sensor_state_lock_);
- sensor_states_[handle]->deadline_ -=
- sensor_states_[handle]->sampling_period_;
- sensor_states_[handle]->sampling_period_ = Nanoseconds(sampling_period_ns);
- sensor_states_[handle]->deadline_ +=
- sensor_states_[handle]->sampling_period_;
- // If our sampling period has decreased, our deadline
- // could have already passed. If so, report immediately, but not in the
- // past.
- MonotonicTimePoint now = MonotonicTimePoint::Now();
- if (sensor_states_[handle]->deadline_ < now) {
- sensor_states_[handle]->deadline_ = now;
- }
- UpdateDeadline();
- }
-
- D("sensor_set_delay(): handle %d, delay (ms) %" PRId64, handle,
- Milliseconds(Nanoseconds(sampling_period_ns)).count());
- if (!UpdateRemoterState(handle)) {
- ALOGE("Failed to notify remoter about new sensor delay.");
- }
- return 0;
-}
-
-int GceSensors::Poll(sensors_event_t* data, int count_unsafe) {
- if (count_unsafe <= 0) {
- ALOGE("Framework polled with bad count (%d)", count_unsafe);
- return -1;
- }
- size_t count = size_t(count_unsafe);
-
- // Poll will block until 1 of 2 things happens:
- // 1. The next deadline for some active sensor
- // occurs.
- // 2. The next deadline changes (either because
- // a sensor was activated/deactivated or its
- // delay changed).
- // In both cases, any sensors whose report deadlines
- // have passed will report their data (or mock data),
- // and poll will either return (if at least one deadline
- // has passed), or repeat by blocking until the next deadline.
- LockGuard<Mutex> guard(sensor_state_lock_);
- current_deadline_ = UpdateDeadline();
- // Sleep until we have something to report
- while (!fifo_.size()) {
- deadline_change_.WaitUntil(current_deadline_);
- current_deadline_ = UpdateDeadline();
- }
- // Copy the events from the buffer
- int num_copied = std::min(fifo_.size(), count);
- FifoType::iterator first_uncopied = fifo_.begin() + num_copied;
- std::copy(fifo_.begin(), first_uncopied, data);
- fifo_.erase(fifo_.begin(), first_uncopied);
- D("Reported %d sensor events. First: %d %f %f %f", num_copied, data->sensor,
- data->data[0], data->data[1], data->data[2]);
- return num_copied;
-}
-
-
-void *GceSensors::Receiver() {
- // Initialize the server.
- sensor_listener_socket_ = cvd::SharedFD::SocketSeqPacketServer(
- gce_sensors_message::kSensorsHALSocketName, 0777);
- if (!sensor_listener_socket_->IsOpen()) {
- ALOGE("GceSensors::%s: Could not listen for sensor connections. (%s).",
- __FUNCTION__, sensor_listener_socket_->StrError());
- return NULL;
- }
- D("GceSensors::%s: Listening for sensor connections at %s", __FUNCTION__,
- gce_sensors_message::kSensorsHALSocketName);
- // Announce that we are ready for the remoter to connect.
- if (!NotifyRemoter()) {
- ALOGI("Failed to notify remoter that HAL is ready.");
- } else {
- ALOGI("Notified remoter that HAL is ready.");
- }
-
- typedef std::vector<cvd::SharedFD> FDVec;
- FDVec connected;
- // Listen for incoming sensor data and control messages
- // from the HAL.
- while (true) {
- cvd::SharedFDSet fds;
- for (FDVec::iterator it = connected.begin(); it != connected.end(); ++it) {
- fds.Set(*it);
- }
- fds.Set(control_receiver_socket_);
- // fds.Set(sensor_listener_socket_);
- int res = cvd::Select(&fds, NULL, NULL, NULL);
- if (res == -1) {
- ALOGE("%s: select returned %d and failed %d -> %s", __FUNCTION__, res,
- errno, strerror(errno));
- break;
- } else if (res == 0) {
- ALOGE("%s: select timed out", __FUNCTION__);
- break;
- } else if (fds.IsSet(sensor_listener_socket_)) {
- connected.push_back(cvd::SharedFD::Accept(*sensor_listener_socket_));
- ALOGI("GceSensors::%s: new client connected", __FUNCTION__);
- } else if (fds.IsSet(control_receiver_socket_)) {
- // We received a control message.
- SensorControlMessage msg;
- int res =
- control_receiver_socket_->Read(&msg, sizeof(SensorControlMessage));
- if (res == -1) {
- ALOGE("GceSensors::%s: Failed to receive control message.",
- __FUNCTION__);
- } else if (res == 0) {
- ALOGE("GceSensors::%s: Control connection closed.", __FUNCTION__);
- }
- if (msg.message_type == SENSOR_STATE_UPDATE) {
- // Forward the update to the remoter.
- remoter_request_packet packet;
- remoter_request_packet_init(&packet, kRemoterSensorState, 0);
- {
- LockGuard<Mutex> guard(sensor_state_lock_);
- packet.params.sensor_state_params.type =
- sensor_infos_[msg.sensor_handle].type;
- packet.params.sensor_state_params.enabled =
- sensor_states_[msg.sensor_handle]->enabled_;
- packet.params.sensor_state_params.delay_ns =
- sensor_states_[msg.sensor_handle]->sampling_period_.count();
- packet.params.sensor_state_params.handle = msg.sensor_handle;
- }
- struct msghdr msg;
- iovec msg_iov[1];
- msg_iov[0].iov_base = &packet;
- msg_iov[0].iov_len = sizeof(remoter_request_packet);
- msg.msg_name = NULL;
- msg.msg_namelen = 0;
- msg.msg_iov = msg_iov;
- msg.msg_iovlen = arraysize(msg_iov);
- msg.msg_control = NULL;
- msg.msg_controllen = 0;
- msg.msg_flags = 0;
-
- for (FDVec::iterator it = connected.begin(); it != connected.end();
- ++it) {
- cvd::SharedFD &fd = *it;
- if (fd->SendMsg(&msg, 0) == -1) {
- ALOGE("GceSensors::%s. Could not send sensor state (%s).",
- __FUNCTION__, fd->StrError());
- }
- }
- }
- if (msg.message_type == THREAD_STOP) {
- D("Received terminate control message.");
- return NULL;
- }
- } else {
- for (FDVec::iterator it = connected.begin(); it != connected.end();
- ++it) {
- cvd::SharedFD &fd = *it;
- if (fds.IsSet(fd)) {
- // We received a sensor update from remoter.
- sensors_event_t event;
- struct msghdr msg;
- iovec msg_iov[1];
- msg_iov[0].iov_base = &event;
- msg_iov[0].iov_len = sizeof(event);
- msg.msg_name = NULL;
- msg.msg_namelen = 0;
- msg.msg_iov = msg_iov;
- msg.msg_iovlen = arraysize(msg_iov);
- msg.msg_control = NULL;
- msg.msg_controllen = 0;
- msg.msg_flags = 0;
- int res = fd->RecvMsg(&msg, 0);
- if (res <= 0) {
- if (res == 0) {
- ALOGE("GceSensors::%s: Sensors HAL connection closed.",
- __FUNCTION__);
- } else {
- ALOGE("GceSensors::%s: Failed to receive sensor message",
- __FUNCTION__);
- }
- connected.erase(std::find(connected.begin(), connected.end(), fd));
- break;
- }
-
- // We received an event from the remoter.
- if (event.sensor < 0 || event.sensor >= total_sensor_count_) {
- ALOGE("Remoter sent us an invalid sensor event! (handle %d)",
- event.sensor);
- connected.erase(std::find(connected.begin(), connected.end(), fd));
- break;
- }
-
- D("Received sensor event: %d %f %f %f", event.sensor, event.data[0],
- event.data[1], event.data[2]);
-
- {
- LockGuard<Mutex> guard(sensor_state_lock_);
- // Increase the delay so that the HAL knows
- // it shouldn't report on its own for a while.
- SensorState *holding_buffer = sensor_states_[event.sensor];
- int wait_periods =
- std::max(kInjectedEventWaitPeriods,
- (int)(kInjectedEventWaitTime.count() /
- holding_buffer->sampling_period_.count()));
- holding_buffer->deadline_ =
- MonotonicTimePoint::Now() +
- holding_buffer->sampling_period_ * wait_periods;
- holding_buffer->event_.data[0] = event.data[0];
- holding_buffer->event_.data[1] = event.data[1];
- holding_buffer->event_.data[2] = event.data[2];
- // Signal the HAL to report the newly arrived event.
- fifo_.push_back(event);
- deadline_change_.NotifyOne();
- }
- }
- }
- }
- }
- return NULL;
-}
-
-bool GceSensors::NotifyRemoter() {
- remoter_request_packet packet;
- remoter_request_packet_init(&packet, kRemoterHALReady, 0);
- packet.send_response = 0;
- strncpy(packet.params.hal_ready_params.unix_socket,
- gce_sensors_message::kSensorsHALSocketName,
- sizeof(packet.params.hal_ready_params.unix_socket));
- AutoCloseFileDescriptor remoter_socket(remoter_connect());
- if (remoter_socket.IsError()) {
- D("GceSensors::%s: Could not connect to remoter to notify ready (%s).",
- __FUNCTION__, strerror(errno));
- return false;
- }
- int err =
- remoter_do_single_request_with_socket(remoter_socket, &packet, NULL);
- if (err == -1) {
- D("GceSensors::%s: Notify remoter ready: Failed after connect (%s).",
- __FUNCTION__, strerror(errno));
- return false;
- }
- D("GceSensors::%s: Notify remoter ready Succeeded.", __FUNCTION__);
- return true;
-}
-
-static bool CompareTimestamps(const sensors_event_t& a,
- const sensors_event_t& b) {
- return a.timestamp < b.timestamp;
-}
-
-MonotonicTimePoint GceSensors::UpdateDeadline() {
- // Get the minimum of all the current deadlines.
- MonotonicTimePoint now = MonotonicTimePoint::Now();
- MonotonicTimePoint min = SensorState::kInfinity;
- int i = 0;
- bool sort_fifo = false;
-
- for (i = 0; i < total_sensor_count_; i++) {
- SensorState* holding_buffer = sensor_states_[i];
- // Ignore disabled sensors.
- if (!holding_buffer->enabled_) {
- continue;
- }
- while (holding_buffer->deadline_ < now) {
- sensors_event_t data = holding_buffer->event_;
- data.timestamp = holding_buffer->deadline_.SinceEpoch().count();
- fifo_.push_back(data);
- holding_buffer->deadline_ += holding_buffer->sampling_period_;
- sort_fifo = true;
- }
- // Now check if we should update the wake time based on the next event
- // from this sensor.
- if (sensor_states_[i]->deadline_ < min) {
- min = sensor_states_[i]->deadline_;
- }
- }
- // We added one or more sensor readings, so do a sort.
- // This is likely to be cheaper than a traditional priority queue because
- // a priority queue would try to keep its state correct for each addition.
- if (sort_fifo) {
- std::sort(fifo_.begin(), fifo_.end(), CompareTimestamps);
- }
- // If we added events or the deadline is lower notify the thread in Poll().
- // If the deadline went up, don't do anything.
- if (fifo_.size() || (min < current_deadline_)) {
- deadline_change_.NotifyOne();
- }
- return min;
-}
-
-bool GceSensors::UpdateRemoterState(int handle) {
- SensorControlMessage msg;
- msg.message_type = SENSOR_STATE_UPDATE;
- msg.sensor_handle = handle;
- return SendControlMessage(msg);
-}
-
-bool GceSensors::SendControlMessage(SensorControlMessage msg) {
- if (!control_sender_socket_->IsOpen()) {
- ALOGE("%s: Can't send control message %d, control socket not open.",
- __FUNCTION__, msg.message_type);
- return false;
- }
- if (control_sender_socket_->Write(&msg, sizeof(SensorControlMessage)) == -1) {
- ALOGE("GceSensors::%s. Could not send control message %d (%s).",
- __FUNCTION__, msg.message_type, control_sender_socket_->StrError());
- return false;
- }
- return true;
-}
-
-int GceSensors::RegisterSensors() {
- if (total_sensor_count_ != -1) {
- return -1;
- }
- total_sensor_count_ = 9;
- sensor_infos_ = new SensorInfo[total_sensor_count_];
- sensor_infos_[sensors_constants::kAccelerometerHandle] =
- AccelerometerSensor();
- sensor_infos_[sensors_constants::kGyroscopeHandle] = GyroscopeSensor();
- sensor_infos_[sensors_constants::kLightHandle] = LightSensor();
- sensor_infos_[sensors_constants::kMagneticFieldHandle] =
- MagneticFieldSensor();
- sensor_infos_[sensors_constants::kPressureHandle] = PressureSensor();
- sensor_infos_[sensors_constants::kProximityHandle] = ProximitySensor();
- sensor_infos_[sensors_constants::kAmbientTempHandle] = AmbientTempSensor();
- sensor_infos_[sensors_constants::kDeviceTempHandle] = DeviceTempSensor();
- sensor_infos_[sensors_constants::kRelativeHumidityHandle] =
- RelativeHumiditySensor();
- int i;
- for (i = 0; i < total_sensor_count_; i++) {
- D("Found sensor %s with handle %d", sensor_infos_[i].name,
- sensor_infos_[i].handle);
- }
- return total_sensor_count_;
-}
-
-} // namespace cvd
diff --git a/guest/hals/sensors/vsoc_sensors.h b/guest/hals/sensors/vsoc_sensors.h
deleted file mode 100644
index c4e9718..0000000
--- a/guest/hals/sensors/vsoc_sensors.h
+++ /dev/null
@@ -1,230 +0,0 @@
-/*
- * 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.
- */
-#pragma once
-
-#include <vector>
-
-#include "common/libs/threads/cuttlefish_thread.h"
-#include "common/libs/fs/shared_fd.h"
-#include "guest/hals/sensors/sensors.h"
-#include "guest/hals/sensors/sensors_hal.h"
-
-namespace cvd {
-
-// Used for sending control messages to the receiver thread.
-// The sensor_handle field may be left unused if it is not needed.
-enum ControlMessageType {
- THREAD_STOP,
- SENSOR_STATE_UPDATE
-};
-typedef struct {
- ControlMessageType message_type;
- uint8_t sensor_handle;
-} SensorControlMessage;
-
-// Last updated to HAL 1.4
-// Version history:
-// Before jb, jb-mr1 SENSORS_DEVICE_API_VERSION_0_1 (no version in sensors.h)
-// jb-mr2: SENSORS_DEVICE_API_VERSION_1_0
-// k: SENSORS_DEVICE_API_VERSION_1_1
-// l, l-mr1: SENSORS_DEVICE_API_VERSION_1_3
-// m, n, n-mr1: SENSORS_DEVICE_API_VERSION_1_4
-
-class GceSensors : public sensors_poll_device_1 {
- public:
- GceSensors();
- ~GceSensors();
-
- /**
- ** SENSOR HAL API FUNCTIONS FOR MODULE
- **/
-
- // Gets a list of all supported sensors and stores in list.
- // Returns the number of supported sensors.
- static int GetSensorsList(struct sensors_module_t* module,
- struct sensor_t const** list);
-
- // Place the module in a specific mode. The following modes are defined
- //
- // 0 - Normal operation. Default state of the module.
- // 1 - Loopback mode. Data is injected for the supported
- // sensors by the sensor service in this mode.
- // @return 0 on success
- // -EINVAL if requested mode is not supported
- // -EPERM if operation is not allowed
- static int SetOperationMode(unsigned int mode);
-
-
- /**
- ** SENSOR HAL API FUNCTIONS FOR DEVICE
- **/
- // Opens the device.
- static int Open(const struct hw_module_t* module, const char* name,
- struct hw_device_t** device);
-
- // Closes the device, closing all sensors.
- int Close();
-
- // Activate (or deactivate) the sensor with the given handle.
- //
- // One-shot sensors deactivate themselves automatically upon receiving an
- // event, and they must still accept to be deactivated through a call to
- // activate(..., enabled=0).
- // Non-wake-up sensors never prevent the SoC from going into suspend mode;
- // that is, the HAL shall not hold a partial wake-lock on behalf of
- // applications.
- //
- // If enabled is 1 and the sensor is already activated, this function is a
- // no-op and succeeds.
- //
- // If enabled is 0 and the sensor is already deactivated, this function is a
- // no-op and succeeds.
- //
- // This function returns 0 on success and a negative error number otherwise.
- int Activate(int handle, int enabled);
-
- // Sets the delay (in ns) for the sensor with the given handle.
- // Deprecated as of HAL 1.1
- // Called after activate()
- int SetDelay(int handle, int64_t sampling_period_ns);
-
- // Returns an array of sensor data by filling the data argument.
- // This function must block until events are available. It will return
- // the number of events read on success, or a negative number in case of
- // an error.
- int Poll(sensors_event_t* data, int count);
-
- // Sets a sensor’s parameters, including sampling frequency and maximum
- // report latency. This function can be called while the sensor is
- // activated, in which case it must not cause any sensor measurements to
- // be lost: transitioning from one sampling rate to the other cannot cause
- // lost events, nor can transitioning from a high maximum report latency to
- // a low maximum report latency.
- //
- // Before SENSORS_DEVICE_API_VERSION_1_3, flags included:
- // SENSORS_BATCH_DRY_RUN
- // SENSORS_BATCH_WAKE_UPON_FIFO_FULL
- //
- // After SENSORS_DEVICE_API_VERSION_1_3 see WAKE_UPON_FIFO_FULL
- // in sensor_t.flags
- int Batch(int sensor_handle, int flags, int64_t sampling_period_ns,
- int64_t max_report_latency_ns) {
- // TODO: Add support for maximum report latency with max_report_latency_ns.
- return SetDelay(sensor_handle, sampling_period_ns);
- }
-
- // Adds a META_DATA_FLUSH_COMPLETE event (sensors_event_meta_data_t)
- // to the end of the "batch mode" FIFO for the specified sensor and flushes
- // the FIFO.
- //
- // If the FIFO is empty or if the sensor doesn't support batching (FIFO
- // size zero), it should return SUCCESS along with a trivial
- // META_DATA_FLUSH_COMPLETE event added to the event stream. This applies to
- // all sensors other than one-shot sensors.
- //
- // If the sensor is a one-shot sensor, flush must return -EINVAL and not
- // generate any flush complete metadata.
- //
- // If the sensor is not active at the time flush() is called, flush() should
- // return -EINVAL.
- int Flush(int sensor_handle) {
- return -EINVAL;
- }
-
- // Inject a single sensor sample to be to this device.
- // data points to the sensor event to be injected
- // @return 0 on success
- // -EPERM if operation is not allowed
- // -EINVAL if sensor event cannot be injected
- int InjectSensorData(const sensors_event_t *data) {
- return -EINVAL;
- }
-
- private:
- typedef std::vector<SensorState*> SensorStateVector;
- typedef std::vector<sensors_event_t> FifoType;
- // Total number of sensors supported by this HAL.
- static int total_sensor_count_;
- // Vector of static sensor information for sensors supported by this HAL.
- // Indexed by the handle. Length must always be equal to total_sensor_count_.
- static SensorInfo* sensor_infos_;
- // Vector of sensor state information, indexed by the handle.
- // Assumption here is that the sensor handles will start at 0 and be
- // contiguous up to the number of supported sensors.
- SensorStateVector sensor_states_;
- // Keep track of the time when the thread in Poll() is scheduled to wake.
- cvd::time::MonotonicTimePoint current_deadline_;
-
- // Ordered set of sensor values.
- // TODO(ghartman): Simulate FIFO overflow.
- FifoType fifo_;
- // Thread to handle new connections.
- pthread_t receiver_thread_;
- // Socket to receive sensor events on.
- cvd::SharedFD sensor_listener_socket_;
- // Socket for listener thread to receive control messages.
- cvd::SharedFD control_receiver_socket_;
- // Socket to send control messages to listener thread.
- cvd::SharedFD control_sender_socket_;
-
- // Lock to protect shared state, including
- // sensor_states_ and next_deadline_.
- // Associated with deadline_change_ condition variable.
- cvd::Mutex sensor_state_lock_;
- // Condition variable to signal changes in the deadline.
- cvd::ConditionVariable deadline_change_;
-
- // When events are arriving from a client, we report only
- // when they arrive, rather than at a fixed cycle. After not
- // receiving a real event for both a given number of periods
- // and a given time period, we will give up and resume
- // sending mock events.
- const static int kInjectedEventWaitPeriods;
- const static cvd::time::Nanoseconds kInjectedEventWaitTime;
-
- /**
- ** UTILITY FUNCTIONS
- **/
-
- // Receive data from remoter.
- void* Receiver();
-
- // Notifies the remoter that the HAL is awake and ready.
- inline bool NotifyRemoter();
-
- // Looks through all active sensor deadlines, and finds the one that
- // is coming up next. If this is not next_deadline_, then the deadline
- // has changed. Update it and signal the Poll thread.
- // This should be called anytime the next deadline may have changed.
- // Can only be called while holding sensor_state_lock_.
- // Returns true if the deadline has changed.
- cvd::time::MonotonicTimePoint UpdateDeadline();
-
- // Sends an update for the sensor with the given handle to the remoter.
- // Update will be enqueued for receiver, not send immediately.
- inline bool UpdateRemoterState(int handle);
-
- // Sends a control event to the listener.
- inline bool SendControlMessage(SensorControlMessage msg);
-
- // Populates the list of static sensor info. Returns the number
- // of sensors supported. Should only be called once.
- static inline int RegisterSensors();
-
-};
-
-} //namespace cvd
-
diff --git a/guest/hals/sensors/vsoc_sensors_message.cpp b/guest/hals/sensors/vsoc_sensors_message.cpp
deleted file mode 100644
index 1998762..0000000
--- a/guest/hals/sensors/vsoc_sensors_message.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * 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 <stdlib.h>
-#include "guest/hals/sensors/vsoc_sensors_message.h"
-
-const char* gce_sensors_message::kSensorsHALSocketName =
- "/var/run/system/sensors_hal_socket";
diff --git a/guest/hals/sensors/vsoc_sensors_message.h b/guest/hals/sensors/vsoc_sensors_message.h
deleted file mode 100644
index 3a57700..0000000
--- a/guest/hals/sensors/vsoc_sensors_message.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * 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.
- */
-#pragma once
-
-#include <hardware/hardware.h>
-#include <hardware/sensors.h>
-
-struct gce_sensors_message : sensors_event_t {
- static const char* kSensorsHALSocketName;
-};
-
diff --git a/host/commands/assemble_cvd/super_image_mixer.cc b/host/commands/assemble_cvd/super_image_mixer.cc
index 6cfa269..2081af4 100644
--- a/host/commands/assemble_cvd/super_image_mixer.cc
+++ b/host/commands/assemble_cvd/super_image_mixer.cc
@@ -15,15 +15,17 @@
#include "super_image_mixer.h"
+#include <sys/stat.h>
+
+#include <algorithm>
#include <cstdio>
#include <functional>
#include <memory>
+#include <android-base/strings.h>
#include <glog/logging.h>
-#include "ziparchive/zip_archive.h"
-#include "ziparchive/zip_writer.h"
-
+#include "common/libs/utils/archive.h"
#include "common/libs/utils/files.h"
#include "common/libs/utils/subprocess.h"
#include "host/libs/config/cuttlefish_config.h"
@@ -49,45 +51,6 @@
return "";
}
-class ZipArchiveDeleter {
-public:
- void operator()(ZipArchive* archive) {
- CloseArchive(archive);
- }
-};
-
-using ManagedZipArchive = std::unique_ptr<ZipArchive, ZipArchiveDeleter>;
-
-class CFileCloser {
-public:
- void operator()(FILE* file) {
- fclose(file);
- }
-};
-
-using ManagedCFile = std::unique_ptr<FILE, CFileCloser>;
-
-ManagedZipArchive OpenZipArchive(const std::string& path) {
- ZipArchive* ptr;
- int status = OpenArchive(path.c_str(), &ptr);
- if (status != 0) {
- LOG(ERROR) << "Could not open archive \"" << path << "\": " << status;
- return {};
- }
- return ManagedZipArchive(ptr);
-}
-
-ManagedCFile OpenFile(const std::string& path, const std::string& mode) {
- FILE* ptr = fopen(path.c_str(), mode.c_str());
- if (ptr == nullptr) {
- int error_num = errno;
- LOG(ERROR) << "Could not open \"" << path << "\". Error was "
- << strerror(error_num);
- return {};
- }
- return ManagedCFile(ptr);
-}
-
const std::string kMiscInfoPath = "META/misc_info.txt";
const std::set<std::string> kDefaultTargetImages = {
"IMAGES/boot.img",
@@ -97,86 +60,67 @@
"IMAGES/vendor.img",
};
-bool CopyZipFileContents(const uint8_t* buf, size_t buf_size, void* cookie) {
- ZipWriter* out_writer = (ZipWriter*) cookie;
- int32_t status = out_writer->WriteBytes(buf, buf_size);
- if (status != 0) {
- LOG(ERROR) << "Could not write zip file contents, error code " << status;
- return false;
- }
- return true;
-}
-
bool CombineTargetZipFiles(const std::string& default_target_zip,
const std::string& system_target_zip,
const std::string& output_path) {
- auto default_target = OpenZipArchive(default_target_zip);
- if (!default_target) {
+ cvd::Archive default_target_archive(default_target_zip);
+ cvd::Archive system_target_archive(system_target_zip);
+
+ auto default_target_contents = default_target_archive.Contents();
+ if (default_target_contents.size() == 0) {
LOG(ERROR) << "Could not open " << default_target_zip;
return false;
}
- auto system_target = OpenZipArchive(system_target_zip);
- if (!system_target) {
+ auto system_target_contents = system_target_archive.Contents();
+ if (system_target_contents.size() == 0) {
LOG(ERROR) << "Could not open " << system_target_zip;
return false;
}
- auto out_file = OpenFile(output_path, "wb");
- if (!out_file) {
- LOG(ERROR) << "Could not open " << output_path;
+ if (mkdir(output_path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0) {
+ LOG(ERROR) << "Could not create directory " << output_path;
return false;
}
- ZipWriter out_writer{out_file.get()};
- ZipEntry entry;
-
- if (FindEntry(default_target.get(), kMiscInfoPath, &entry) != 0) {
+ if (std::find(default_target_contents.begin(), default_target_contents.end(), kMiscInfoPath)
+ == default_target_contents.end()) {
LOG(ERROR) << "Default target files zip does not have " << kMiscInfoPath;
return false;
}
- out_writer.StartEntry(kMiscInfoPath, 0);
- ProcessZipEntryContents(
- default_target.get(), &entry, CopyZipFileContents, (void*) &out_writer);
- out_writer.FinishEntry();
-
- void* iteration_cookie;
- std::string name;
-
- StartIteration(default_target.get(), &iteration_cookie, "IMAGES/", ".img");
- for (int status = 0; status != -1; status = Next(iteration_cookie, &entry, &name)) {
- if (name == "") {
- continue;
- }
- LOG(INFO) << "Name is \"" << name << "\"";
- if (kDefaultTargetImages.count(name) == 0) {
- continue;
- }
- LOG(INFO) << "Writing " << name;
- out_writer.StartEntry(name, 0);
- ProcessZipEntryContents(
- default_target.get(), &entry, CopyZipFileContents, (void*) &out_writer);
- out_writer.FinishEntry();
- }
- EndIteration(iteration_cookie);
-
- StartIteration(system_target.get(), &iteration_cookie, "IMAGES/", ".img");
- for (int status = 0; status != -1; status = Next(iteration_cookie, &entry, &name)) {
- if (kDefaultTargetImages.count(name) > 0) {
- continue;
- }
- LOG(INFO) << "Writing " << name;
- out_writer.StartEntry(name, 0);
- ProcessZipEntryContents(
- system_target.get(), &entry, CopyZipFileContents, (void*) &out_writer);
- out_writer.FinishEntry();
- }
- EndIteration(iteration_cookie);
-
- int success = out_writer.Finish();
- if (success != 0) {
- LOG(ERROR) << "Unable to write combined image zip archive: " << success;
+ if (!default_target_archive.ExtractFiles({kMiscInfoPath}, output_path)) {
+ LOG(ERROR) << "Failed to write misc info to output directory";
return false;
}
+ for (const auto& name : default_target_contents) {
+ if (!android::base::StartsWith(name, "IMAGES/")) {
+ continue;
+ } else if (!android::base::EndsWith(name, ".img")) {
+ continue;
+ } else if (kDefaultTargetImages.count(name) == 0) {
+ continue;
+ }
+ LOG(INFO) << "Writing " << name;
+ if (!default_target_archive.ExtractFiles({name}, output_path)) {
+ LOG(ERROR) << "Failed to extract " << name << " from the default target zip";
+ return false;
+ }
+ }
+
+ for (const auto& name : system_target_contents) {
+ if (!android::base::StartsWith(name, "IMAGES/")) {
+ continue;
+ } else if (!android::base::EndsWith(name, ".img")) {
+ continue;
+ } else if (kDefaultTargetImages.count(name) > 0) {
+ continue;
+ }
+ LOG(INFO) << "Writing " << name;
+ if (!system_target_archive.ExtractFiles({name}, output_path)) {
+ LOG(ERROR) << "Failed to extract " << name << " from the system target zip";
+ return false;
+ }
+ }
+
return true;
}
@@ -235,14 +179,14 @@
LOG(ERROR) << "Unable to find system target zip file.";
return false;
}
- std::string combined_target_zip = config.PerInstancePath("target_combined.zip");
+ std::string combined_target_path = config.PerInstanceInternalPath("target_combined");
// TODO(schuffelen): Use otatools/bin/merge_target_files
if (!CombineTargetZipFiles(default_target_zip, system_target_zip,
- combined_target_zip)) {
+ combined_target_path)) {
LOG(ERROR) << "Could not combine target zip files.";
return false;
}
- bool success = BuildSuperImage(combined_target_zip, output_path);
+ bool success = BuildSuperImage(combined_target_path, output_path);
if (!success) {
LOG(ERROR) << "Could not write the final output super image.";
}