Merge "Fix bugprone-use-after-move warnings" into rvc-dev
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp
index beab270..9642a87 100644
--- a/libs/binder/Parcel.cpp
+++ b/libs/binder/Parcel.cpp
@@ -987,12 +987,22 @@
status_t Parcel::writeString8(const String8& str)
{
- status_t err = writeInt32(str.bytes());
- // only write string if its length is more than zero characters,
- // as readString8 will only read if the length field is non-zero.
- // this is slightly different from how writeString16 works.
- if (str.bytes() > 0 && err == NO_ERROR) {
- err = write(str.string(), str.bytes()+1);
+ return writeString8(str.string(), str.size());
+}
+
+status_t Parcel::writeString8(const char* str, size_t len)
+{
+ if (str == nullptr) return writeInt32(-1);
+
+ status_t err = writeInt32(len);
+ if (err == NO_ERROR) {
+ uint8_t* data = (uint8_t*)writeInplace(len+sizeof(char));
+ if (data) {
+ memcpy(data, str, len);
+ *reinterpret_cast<char*>(data+len) = 0;
+ return NO_ERROR;
+ }
+ err = mError;
}
return err;
}
@@ -1832,37 +1842,39 @@
String8 Parcel::readString8() const
{
- String8 retString;
- status_t status = readString8(&retString);
- if (status != OK) {
- // We don't care about errors here, so just return an empty string.
- return String8();
- }
- return retString;
+ size_t len;
+ const char* str = readString8Inplace(&len);
+ if (str) return String8(str, len);
+ ALOGE("Reading a NULL string not supported here.");
+ return String8();
}
status_t Parcel::readString8(String8* pArg) const
{
- int32_t size;
- status_t status = readInt32(&size);
- if (status != OK) {
- return status;
- }
- // watch for potential int overflow from size+1
- if (size < 0 || size >= INT32_MAX) {
- return BAD_VALUE;
- }
- // |writeString8| writes nothing for empty string.
- if (size == 0) {
+ size_t len;
+ const char* str = readString8Inplace(&len);
+ if (str) {
+ pArg->setTo(str, len);
+ return 0;
+ } else {
*pArg = String8();
- return OK;
+ return UNEXPECTED_NULL;
}
- const char* str = (const char*)readInplace(size + 1);
- if (str == nullptr) {
- return BAD_VALUE;
+}
+
+const char* Parcel::readString8Inplace(size_t* outLen) const
+{
+ int32_t size = readInt32();
+ // watch for potential int overflow from size+1
+ if (size >= 0 && size < INT32_MAX) {
+ *outLen = size;
+ const char* str = (const char*)readInplace(size+1);
+ if (str != nullptr) {
+ return str;
+ }
}
- pArg->setTo(str, size);
- return OK;
+ *outLen = 0;
+ return nullptr;
}
String16 Parcel::readString16() const
diff --git a/libs/binder/include/binder/Parcel.h b/libs/binder/include/binder/Parcel.h
index 4b1a758..c1f64fb 100644
--- a/libs/binder/include/binder/Parcel.h
+++ b/libs/binder/include/binder/Parcel.h
@@ -119,6 +119,7 @@
status_t writeDouble(double val);
status_t writeCString(const char* str);
status_t writeString8(const String8& str);
+ status_t writeString8(const char* str, size_t len);
status_t writeString16(const String16& str);
status_t writeString16(const std::unique_ptr<String16>& str);
status_t writeString16(const char16_t* str, size_t len);
@@ -283,6 +284,7 @@
const char* readCString() const;
String8 readString8() const;
status_t readString8(String8* pArg) const;
+ const char* readString8Inplace(size_t* outLen) const;
String16 readString16() const;
status_t readString16(String16* pArg) const;
status_t readString16(std::unique_ptr<String16>* pArg) const;
diff --git a/services/sensorservice/SensorDevice.cpp b/services/sensorservice/SensorDevice.cpp
index aa6f1b8..3b68e0e 100644
--- a/services/sensorservice/SensorDevice.cpp
+++ b/services/sensorservice/SensorDevice.cpp
@@ -143,14 +143,6 @@
for (size_t i=0 ; i < count; i++) {
sensor_t sensor;
convertToSensor(convertToOldSensorInfo(list[i]), &sensor);
-
- if (sensor.resolution == 0) {
- // Don't crash here or the device will go into a crashloop.
- ALOGE("%s must have a non-zero resolution", sensor.name);
- // For simple algos, map their resolution to 1 if it's not specified
- sensor.resolution = SensorDeviceUtils::defaultResolutionForType(sensor.type);
- }
-
// Sanity check and clamp power if it is 0 (or close)
if (sensor.power < minPowerMa) {
ALOGI("Reported power %f not deemed sane, clamping to %f",
@@ -516,7 +508,7 @@
const auto &events,
const auto &dynamicSensorsAdded) {
if (result == Result::OK) {
- convertToSensorEventsAndQuantize(convertToNewEvents(events),
+ convertToSensorEvents(convertToNewEvents(events),
convertToNewSensorInfos(dynamicSensorsAdded), buffer);
err = (ssize_t)events.size();
} else {
@@ -579,8 +571,6 @@
for (size_t i = 0; i < eventsToRead; i++) {
convertToSensorEvent(mEventBuffer[i], &buffer[i]);
- android::SensorDeviceUtils::quantizeSensorEventValues(&buffer[i],
- getResolutionForSensor(buffer[i].sensor));
}
eventsRead = eventsToRead;
} else {
@@ -1087,7 +1077,7 @@
}
}
-void SensorDevice::convertToSensorEventsAndQuantize(
+void SensorDevice::convertToSensorEvents(
const hidl_vec<Event> &src,
const hidl_vec<SensorInfo> &dynamicSensorsAdded,
sensors_event_t *dst) {
@@ -1098,26 +1088,9 @@
for (size_t i = 0; i < src.size(); ++i) {
V2_1::implementation::convertToSensorEvent(src[i], &dst[i]);
- android::SensorDeviceUtils::quantizeSensorEventValues(&dst[i],
- getResolutionForSensor(dst[i].sensor));
}
}
-float SensorDevice::getResolutionForSensor(int sensorHandle) {
- for (size_t i = 0; i < mSensorList.size(); i++) {
- if (sensorHandle == mSensorList[i].handle) {
- return mSensorList[i].resolution;
- }
- }
-
- auto it = mConnectedDynamicSensors.find(sensorHandle);
- if (it != mConnectedDynamicSensors.end()) {
- return it->second->resolution;
- }
-
- return 0;
-}
-
void SensorDevice::handleHidlDeath(const std::string & detail) {
if (!mSensors->supportsMessageQueues()) {
// restart is the only option at present.
diff --git a/services/sensorservice/SensorDevice.h b/services/sensorservice/SensorDevice.h
index 04e6031..24d03c6 100644
--- a/services/sensorservice/SensorDevice.h
+++ b/services/sensorservice/SensorDevice.h
@@ -233,13 +233,11 @@
void convertToSensorEvent(const Event &src, sensors_event_t *dst);
- void convertToSensorEventsAndQuantize(
+ void convertToSensorEvents(
const hardware::hidl_vec<Event> &src,
const hardware::hidl_vec<SensorInfo> &dynamicSensorsAdded,
sensors_event_t *dst);
- float getResolutionForSensor(int sensorHandle);
-
bool mIsDirectReportSupported;
typedef hardware::MessageQueue<uint32_t, hardware::kSynchronizedReadWrite> WakeLockQueue;
diff --git a/services/sensorservice/SensorDeviceUtils.cpp b/services/sensorservice/SensorDeviceUtils.cpp
index 6bf62e4..dbafffe 100644
--- a/services/sensorservice/SensorDeviceUtils.cpp
+++ b/services/sensorservice/SensorDeviceUtils.cpp
@@ -17,112 +17,16 @@
#include "SensorDeviceUtils.h"
#include <android/hardware/sensors/1.0/ISensors.h>
-#include <android/hardware/sensors/2.1/ISensors.h>
#include <utils/Log.h>
#include <chrono>
-#include <cmath>
#include <thread>
using ::android::hardware::Void;
-using SensorTypeV2_1 = android::hardware::sensors::V2_1::SensorType;
using namespace android::hardware::sensors::V1_0;
namespace android {
namespace SensorDeviceUtils {
-namespace {
-
-inline void quantizeValue(float *value, double resolution) {
- // Increase the value of the sensor's nominal resolution to ensure that
- // sensor accuracy improvements, like runtime calibration, are not masked
- // during requantization.
- double incRes = 0.25 * resolution;
- *value = round(static_cast<double>(*value) / incRes) * incRes;
-}
-
-} // namespace
-
-void quantizeSensorEventValues(sensors_event_t *event, float resolution) {
- LOG_FATAL_IF(resolution == 0, "Resolution must be specified for all sensors!");
- if (resolution == 0) {
- return;
- }
-
- size_t axes = 0;
- switch ((SensorTypeV2_1)event->type) {
- case SensorTypeV2_1::ACCELEROMETER:
- case SensorTypeV2_1::MAGNETIC_FIELD:
- case SensorTypeV2_1::ORIENTATION:
- case SensorTypeV2_1::GYROSCOPE:
- case SensorTypeV2_1::GRAVITY:
- case SensorTypeV2_1::LINEAR_ACCELERATION:
- case SensorTypeV2_1::MAGNETIC_FIELD_UNCALIBRATED:
- case SensorTypeV2_1::GYROSCOPE_UNCALIBRATED:
- case SensorTypeV2_1::ACCELEROMETER_UNCALIBRATED:
- axes = 3;
- break;
- case SensorTypeV2_1::GAME_ROTATION_VECTOR:
- axes = 4;
- break;
- case SensorTypeV2_1::ROTATION_VECTOR:
- case SensorTypeV2_1::GEOMAGNETIC_ROTATION_VECTOR:
- axes = 5;
- break;
- case SensorTypeV2_1::DEVICE_ORIENTATION:
- case SensorTypeV2_1::LIGHT:
- case SensorTypeV2_1::PRESSURE:
- case SensorTypeV2_1::TEMPERATURE:
- case SensorTypeV2_1::PROXIMITY:
- case SensorTypeV2_1::RELATIVE_HUMIDITY:
- case SensorTypeV2_1::AMBIENT_TEMPERATURE:
- case SensorTypeV2_1::SIGNIFICANT_MOTION:
- case SensorTypeV2_1::STEP_DETECTOR:
- case SensorTypeV2_1::TILT_DETECTOR:
- case SensorTypeV2_1::WAKE_GESTURE:
- case SensorTypeV2_1::GLANCE_GESTURE:
- case SensorTypeV2_1::PICK_UP_GESTURE:
- case SensorTypeV2_1::WRIST_TILT_GESTURE:
- case SensorTypeV2_1::STATIONARY_DETECT:
- case SensorTypeV2_1::MOTION_DETECT:
- case SensorTypeV2_1::HEART_BEAT:
- case SensorTypeV2_1::LOW_LATENCY_OFFBODY_DETECT:
- case SensorTypeV2_1::HINGE_ANGLE:
- axes = 1;
- break;
- case SensorTypeV2_1::POSE_6DOF:
- axes = 15;
- break;
- default:
- // No other sensors have data that needs to be rounded.
- break;
- }
-
- // sensor_event_t is a union so we're able to perform the same quanitization action for most
- // sensors by only knowing the number of axes their output data has.
- for (size_t i = 0; i < axes; i++) {
- quantizeValue(&event->data[i], resolution);
- }
-}
-
-float defaultResolutionForType(int type) {
- switch ((SensorTypeV2_1)type) {
- case SensorTypeV2_1::SIGNIFICANT_MOTION:
- case SensorTypeV2_1::STEP_DETECTOR:
- case SensorTypeV2_1::STEP_COUNTER:
- case SensorTypeV2_1::TILT_DETECTOR:
- case SensorTypeV2_1::WAKE_GESTURE:
- case SensorTypeV2_1::GLANCE_GESTURE:
- case SensorTypeV2_1::PICK_UP_GESTURE:
- case SensorTypeV2_1::WRIST_TILT_GESTURE:
- case SensorTypeV2_1::STATIONARY_DETECT:
- case SensorTypeV2_1::MOTION_DETECT:
- return 1.0f;
- default:
- // fall through and return 0 for all other types
- break;
- }
- return 0.0f;
-}
HidlServiceRegistrationWaiter::HidlServiceRegistrationWaiter() {
}
diff --git a/services/sensorservice/SensorDeviceUtils.h b/services/sensorservice/SensorDeviceUtils.h
index b66542c..e2eb606 100644
--- a/services/sensorservice/SensorDeviceUtils.h
+++ b/services/sensorservice/SensorDeviceUtils.h
@@ -18,7 +18,6 @@
#define ANDROID_SENSOR_DEVICE_UTIL
#include <android/hidl/manager/1.0/IServiceNotification.h>
-#include <hardware/sensors.h>
#include <condition_variable>
#include <thread>
@@ -30,12 +29,6 @@
namespace android {
namespace SensorDeviceUtils {
-// Ensures a sensor event doesn't provide values finer grained than its sensor resolution allows.
-void quantizeSensorEventValues(sensors_event_t *event, float resolution);
-
-// Provides a default resolution for simple sensor types if one wasn't provided by the HAL.
-float defaultResolutionForType(int type);
-
class HidlServiceRegistrationWaiter : public IServiceNotification {
public: