Commit 89fd25bc authored by Jun Cai's avatar Jun Cai Committed by Commit Bot

Override PlatformSensor::GetMaximumSupportedFrequency() in PlatformSensorFusion

This is a follow-up CL for:
https://chromium-review.googlesource.com/c/chromium/src/+/879586
which clamps sensor frequency to maximum supported frequency.

However, for fusion sensor, it needs to override
PlatformSensor::GetMaximumSupportedFrequency(), otherwise it will get 5Hz as default.
This has caused DeviceOrientation API to report sensor data in a low frequency. This
CL fixes this issue.

Bug: 819413
Change-Id: Ib7c888227d3a09c7df281c06a7dbb3290de34d4f
Reviewed-on: https://chromium-review.googlesource.com/953127Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Commit-Queue: Jun Cai <juncai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#541840}
parent 56fd0636
...@@ -51,7 +51,7 @@ mojom::ReportingMode FakePlatformSensor::GetReportingMode() { ...@@ -51,7 +51,7 @@ mojom::ReportingMode FakePlatformSensor::GetReportingMode() {
} }
double FakePlatformSensor::GetMaximumSupportedFrequency() { double FakePlatformSensor::GetMaximumSupportedFrequency() {
return 50.0; return maximum_supported_frequency_;
} }
double FakePlatformSensor::GetMinimumSupportedFrequency() { double FakePlatformSensor::GetMinimumSupportedFrequency() {
......
...@@ -22,6 +22,10 @@ class FakePlatformSensor : public PlatformSensor { ...@@ -22,6 +22,10 @@ class FakePlatformSensor : public PlatformSensor {
MOCK_METHOD1(StartSensor, MOCK_METHOD1(StartSensor,
bool(const PlatformSensorConfiguration& configuration)); bool(const PlatformSensorConfiguration& configuration));
void set_maximum_supported_frequency(double maximum_supported_frequency) {
maximum_supported_frequency_ = maximum_supported_frequency;
}
protected: protected:
void StopSensor() override {} void StopSensor() override {}
...@@ -35,6 +39,8 @@ class FakePlatformSensor : public PlatformSensor { ...@@ -35,6 +39,8 @@ class FakePlatformSensor : public PlatformSensor {
double GetMaximumSupportedFrequency() override; double GetMaximumSupportedFrequency() override;
double GetMinimumSupportedFrequency() override; double GetMinimumSupportedFrequency() override;
double maximum_supported_frequency_ = 50.0;
~FakePlatformSensor() override; ~FakePlatformSensor() override;
DISALLOW_COPY_AND_ASSIGN(FakePlatformSensor); DISALLOW_COPY_AND_ASSIGN(FakePlatformSensor);
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "services/device/generic_sensor/platform_sensor_fusion.h" #include "services/device/generic_sensor/platform_sensor_fusion.h"
#include <algorithm>
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "services/device/generic_sensor/platform_sensor_fusion_algorithm.h" #include "services/device/generic_sensor/platform_sensor_fusion_algorithm.h"
...@@ -144,7 +146,10 @@ bool PlatformSensorFusion::StartSensor( ...@@ -144,7 +146,10 @@ bool PlatformSensorFusion::StartSensor(
// Remove all the previously added source configs. // Remove all the previously added source configs.
StopSensor(); StopSensor();
for (const auto& pair : source_sensors_) { for (const auto& pair : source_sensors_) {
if (!pair.second->StartListening(this, configuration)) { if (!pair.second->StartListening(
this, PlatformSensorConfiguration(
std::min(configuration.frequency(),
pair.second->GetMaximumSupportedFrequency())))) {
StopSensor(); StopSensor();
return false; return false;
} }
...@@ -164,12 +169,23 @@ void PlatformSensorFusion::StopSensor() { ...@@ -164,12 +169,23 @@ void PlatformSensorFusion::StopSensor() {
bool PlatformSensorFusion::CheckSensorConfiguration( bool PlatformSensorFusion::CheckSensorConfiguration(
const PlatformSensorConfiguration& configuration) { const PlatformSensorConfiguration& configuration) {
for (const auto& pair : source_sensors_) { for (const auto& pair : source_sensors_) {
if (!pair.second->CheckSensorConfiguration(configuration)) if (!pair.second->CheckSensorConfiguration(PlatformSensorConfiguration(
std::min(configuration.frequency(),
pair.second->GetMaximumSupportedFrequency()))))
return false; return false;
} }
return true; return true;
} }
double PlatformSensorFusion::GetMaximumSupportedFrequency() {
double maximum_frequency = 0.0;
for (const auto& pair : source_sensors_) {
maximum_frequency = std::max(maximum_frequency,
pair.second->GetMaximumSupportedFrequency());
}
return maximum_frequency;
}
void PlatformSensorFusion::OnSensorReadingChanged(mojom::SensorType type) { void PlatformSensorFusion::OnSensorReadingChanged(mojom::SensorType type) {
SensorReading reading; SensorReading reading;
reading.raw.timestamp = reading.raw.timestamp =
......
...@@ -48,6 +48,7 @@ class PlatformSensorFusion : public PlatformSensor, ...@@ -48,6 +48,7 @@ class PlatformSensorFusion : public PlatformSensor,
PlatformSensorConfiguration GetDefaultConfiguration() override; PlatformSensorConfiguration GetDefaultConfiguration() override;
bool CheckSensorConfiguration( bool CheckSensorConfiguration(
const PlatformSensorConfiguration& configuration) override; const PlatformSensorConfiguration& configuration) override;
double GetMaximumSupportedFrequency() override;
// PlatformSensor::Client: // PlatformSensor::Client:
void OnSensorReadingChanged(mojom::SensorType type) override; void OnSensorReadingChanged(mojom::SensorType type) override;
......
...@@ -328,4 +328,33 @@ TEST_F(PlatformSensorFusionTest, ...@@ -328,4 +328,33 @@ TEST_F(PlatformSensorFusionTest,
EXPECT_FALSE(fusion_sensor_); EXPECT_FALSE(fusion_sensor_);
} }
TEST_F(PlatformSensorFusionTest,
FusionSensorMaximumSupportedFrequencyIsTheMaximumOfItsSourceSensors) {
EXPECT_FALSE(provider_->GetSensor(SensorType::ACCELEROMETER));
CreateAccelerometer();
scoped_refptr<PlatformSensor> accelerometer =
provider_->GetSensor(SensorType::ACCELEROMETER);
EXPECT_TRUE(accelerometer);
static_cast<FakePlatformSensor*>(accelerometer.get())
->set_maximum_supported_frequency(30.0);
EXPECT_FALSE(provider_->GetSensor(SensorType::MAGNETOMETER));
CreateMagnetometer();
scoped_refptr<PlatformSensor> magnetometer =
provider_->GetSensor(SensorType::MAGNETOMETER);
EXPECT_TRUE(magnetometer);
static_cast<FakePlatformSensor*>(magnetometer.get())
->set_maximum_supported_frequency(20.0);
CreateAbsoluteOrientationEulerAnglesFusionSensor();
EXPECT_TRUE(fusion_sensor_);
EXPECT_EQ(SensorType::ABSOLUTE_ORIENTATION_EULER_ANGLES,
fusion_sensor_->GetType());
EXPECT_EQ(30.0, fusion_sensor_->GetMaximumSupportedFrequency());
auto client = std::make_unique<testing::NiceMock<MockPlatformSensorClient>>(
fusion_sensor_);
EXPECT_TRUE(fusion_sensor_->StartListening(
client.get(), PlatformSensorConfiguration(30.0)));
}
} // namespace device } // namespace device
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment