summaryrefslogtreecommitdiff
path: root/chromium/services/device/generic_sensor/platform_sensor_and_provider_unittest_linux.cc
blob: 4af5f198568a68da5c60ba0a7d767267123d13b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <algorithm>
#include <memory>

#include "base/bind.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/memory/ptr_util.h"
#include "base/numerics/math_constants.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/test/bind.h"
#include "base/test/task_environment.h"
#include "base/threading/thread_restrictions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/chromeos_buildflags.h"
#include "services/device/generic_sensor/generic_sensor_consts.h"
#include "services/device/generic_sensor/linux/sensor_data_linux.h"
#include "services/device/generic_sensor/linux/sensor_device_manager.h"
#include "services/device/generic_sensor/platform_sensor_provider_linux.h"
#include "services/device/generic_sensor/platform_sensor_util.h"
#include "services/device/public/cpp/generic_sensor/sensor_traits.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/angle_conversions.h"

using ::testing::_;
using ::testing::Invoke;
using ::testing::IsNull;
using ::testing::NiceMock;
using ::testing::NotNull;
using ::testing::Return;

namespace device {

namespace {

using mojom::SensorType;

constexpr size_t kSensorValuesSize = 3;

// Zero value can mean whether value is not being not used or zero value.
constexpr double kZero = 0.0;

constexpr double kAmbientLightFrequencyValue = 10.0;

constexpr double kAccelerometerFrequencyValue = 10.0;
constexpr double kAccelerometerOffsetValue = 1.0;
constexpr double kAccelerometerScalingValue = 0.009806;

constexpr double kGyroscopeFrequencyValue = 6.0;
constexpr double kGyroscopeOffsetValue = 2.0;
constexpr double kGyroscopeScalingValue = 0.000017;

constexpr double kMagnetometerFrequencyValue = 7.0;
constexpr double kMagnetometerOffsetValue = 3.0;
constexpr double kMagnetometerScalingValue = 0.000001;

void WriteValueToFile(const base::FilePath& path, double value) {
  const std::string str = base::NumberToString(value);
  int bytes_written = base::WriteFile(path, str.data(), str.size());
  EXPECT_EQ(static_cast<size_t>(bytes_written), str.size());
}

std::string ReadValueFromFile(const base::FilePath& path,
                              const std::string& file) {
  base::FilePath file_path = base::FilePath(path).Append(file);
  std::string new_read_value;
  if (!base::ReadFileToString(file_path, &new_read_value))
    return std::string();
  return new_read_value;
}

double RoundAccelerometerValue(double value) {
  return RoundToMultiple(value, kAccelerometerRoundingMultiple);
}

double RoundGyroscopeValue(double value) {
  return RoundToMultiple(value, kGyroscopeRoundingMultiple);
}

}  // namespace

// Mock for SensorDeviceService that SensorDeviceManager owns.
// This mock is used to emulate udev events and send found sensor devices
// to SensorDeviceManager.
class MockSensorDeviceManager : public SensorDeviceManager {
 public:
  MockSensorDeviceManager(const MockSensorDeviceManager&) = delete;
  MockSensorDeviceManager& operator=(const MockSensorDeviceManager&) = delete;

  ~MockSensorDeviceManager() override = default;

  // static
  static std::unique_ptr<NiceMock<MockSensorDeviceManager>> Create(
      base::WeakPtr<SensorDeviceManager::Delegate> delegate) {
    auto device_manager =
        std::make_unique<NiceMock<MockSensorDeviceManager>>(delegate);
    {
      base::ScopedAllowBlockingForTesting allow_blocking;
      if (!device_manager->sensors_dir_.CreateUniqueTempDir())
        return nullptr;
    }

    const base::FilePath& base_path = device_manager->GetSensorsBasePath();

    ON_CALL(*device_manager, GetUdevDeviceGetSubsystem(IsNull()))
        .WillByDefault(Invoke([](udev_device*) { return "iio"; }));

    ON_CALL(*device_manager, GetUdevDeviceGetSyspath(IsNull()))
        .WillByDefault(
            Invoke([base_path](udev_device*) { return base_path.value(); }));

    ON_CALL(*device_manager, GetUdevDeviceGetDevnode(IsNull()))
        .WillByDefault(Invoke([](udev_device*) { return "/dev/test"; }));

    ON_CALL(*device_manager, GetUdevDeviceGetSysattrValue(IsNull(), _))
        .WillByDefault(
            Invoke([base_path](udev_device*, const std::string& attribute) {
              base::ScopedAllowBlockingForTesting allow_blocking;
              return ReadValueFromFile(base_path, attribute);
            }));

    return device_manager;
  }

  MOCK_METHOD1(GetUdevDeviceGetSubsystem, std::string(udev_device*));
  MOCK_METHOD1(GetUdevDeviceGetSyspath, std::string(udev_device*));
  MOCK_METHOD1(GetUdevDeviceGetDevnode, std::string(udev_device* dev));
  MOCK_METHOD2(GetUdevDeviceGetSysattrValue,
               std::string(udev_device*, const std::string&));
  MOCK_METHOD0(Start, void());

  const base::FilePath& GetSensorsBasePath() const {
    return sensors_dir_.GetPath();
  }

  void EnumerationReady() {
    bool success = delegate_task_runner_->PostTask(
        FROM_HERE,
        base::BindOnce(&SensorDeviceManager::Delegate::OnSensorNodesEnumerated,
                       delegate_));
    ASSERT_TRUE(success);
  }

  void DeviceAdded() {
    SensorDeviceManager::OnDeviceAdded(nullptr /* unused */);
  }

  void DeviceRemoved() {
    SensorDeviceManager::OnDeviceRemoved(nullptr /* unused */);
  }

 protected:
  explicit MockSensorDeviceManager(
      base::WeakPtr<SensorDeviceManager::Delegate> delegate)
      : SensorDeviceManager(std::move(delegate)) {}

 private:
  base::ScopedTempDir sensors_dir_;
};

// Mock for PlatformSensor's client interface that is used to deliver
// error and data changes notifications.
class LinuxMockPlatformSensorClient : public PlatformSensor::Client {
 public:
  explicit LinuxMockPlatformSensorClient(scoped_refptr<PlatformSensor> sensor)
      : sensor_(sensor) {
    if (sensor_)
      sensor_->AddClient(this);

    ON_CALL(*this, IsSuspended()).WillByDefault(Return(false));
  }

  LinuxMockPlatformSensorClient(const LinuxMockPlatformSensorClient&) = delete;
  LinuxMockPlatformSensorClient& operator=(
      const LinuxMockPlatformSensorClient&) = delete;

  ~LinuxMockPlatformSensorClient() override {
    if (sensor_)
      sensor_->RemoveClient(this);
  }

  // PlatformSensor::Client interface.
  MOCK_METHOD1(OnSensorReadingChanged, void(mojom::SensorType type));
  MOCK_METHOD0(OnSensorError, void());
  MOCK_METHOD0(IsSuspended, bool());

 private:
  scoped_refptr<PlatformSensor> sensor_;
};

class PlatformSensorAndProviderLinuxTest : public ::testing::Test {
 public:
  void SetUp() override {
    provider_ = base::WrapUnique(new PlatformSensorProviderLinux);
    provider_->SetSensorDeviceManagerForTesting(MockSensorDeviceManager::Create(
        provider_->weak_ptr_factory_.GetWeakPtr()));
  }

 protected:
  MockSensorDeviceManager* mock_sensor_device_manager() const {
    return static_cast<MockSensorDeviceManager*>(
        provider_->sensor_device_manager_.get());
  }

  // Sensor creation is asynchronous, therefore inner loop is used to wait for
  // PlatformSensorProvider::CreateSensorCallback completion.
  scoped_refptr<PlatformSensor> CreateSensor(mojom::SensorType type) {
    scoped_refptr<PlatformSensor> sensor;
    base::RunLoop run_loop;
    provider_->CreateSensor(type,
                            base::BindLambdaForTesting(
                                [&](scoped_refptr<PlatformSensor> new_sensor) {
                                  sensor = std::move(new_sensor);
                                  run_loop.Quit();
                                }));
    run_loop.Run();
    return sensor;
  }

  // Creates sensor files according to SensorPathsLinux.
  // Existence of sensor read files mean existence of a sensor.
  // If |frequency| or |scaling| is zero, the corresponding file is not created.
  void InitializeSupportedSensor(SensorType type,
                                 double frequency,
                                 double offset,
                                 double scaling,
                                 double values[kSensorValuesSize]) {
    SensorPathsLinux data;
    EXPECT_TRUE(InitSensorData(type, &data));

    {
      base::ScopedAllowBlockingForTesting allow_blocking;

      const base::FilePath& sensor_dir =
          mock_sensor_device_manager()->GetSensorsBasePath();
      if (!data.sensor_scale_name.empty() && scaling != 0) {
        base::FilePath sensor_scale_file =
            base::FilePath(sensor_dir).Append(data.sensor_scale_name);
        WriteValueToFile(sensor_scale_file, scaling);
      }

      if (!data.sensor_offset_file_name.empty()) {
        base::FilePath sensor_offset_file =
            base::FilePath(sensor_dir).Append(data.sensor_offset_file_name);
        WriteValueToFile(sensor_offset_file, offset);
      }

      if (!data.sensor_frequency_file_name.empty() && frequency != 0) {
        base::FilePath sensor_frequency_file =
            base::FilePath(sensor_dir).Append(data.sensor_frequency_file_name);
        WriteValueToFile(sensor_frequency_file, frequency);
      }

      // |data.sensor_file_names| is a vector of std::vector<std::string>s. It
      // is expected to hold at most kSensorValuesSize entries, and each value
      // at position N in |values| will be written to the first entry of the
      // inner vector at position N in |sensor_file_names|.
      EXPECT_LE(data.sensor_file_names.size(), kSensorValuesSize);
      for (size_t i = 0;
           i < std::min(kSensorValuesSize, data.sensor_file_names.size());
           i++) {
        const auto& paths = data.sensor_file_names[i];
        if (paths.empty())
          continue;
        // We write to paths[0] simply because we do not need to write to the
        // other entries in any of the existing tests. This could be changed and
        // parameterized in the future if necessary.
        const auto sensor_file = base::FilePath(sensor_dir).Append(paths[0]);
        WriteValueToFile(sensor_file, values[i]);
      }
    }
  }

  // Emulates device enumerations and initial udev events. Once all
  // devices are added, tells manager its ready.
  void SetServiceStart() {
    auto* manager = mock_sensor_device_manager();
    EXPECT_CALL(*manager, Start()).WillOnce(Invoke([manager]() {
      manager->DeviceAdded();
      manager->EnumerationReady();
    }));
  }

  // Waits before OnSensorReadingChanged is called.
  void WaitOnSensorReadingChangedEvent(LinuxMockPlatformSensorClient* client,
                                       mojom::SensorType type) {
    base::RunLoop run_loop;
    EXPECT_CALL(*client, OnSensorReadingChanged(type))
        .WillOnce(Invoke([&](mojom::SensorType type) { run_loop.Quit(); }));
    run_loop.Run();
  }

  // Waits before OnSensorError is called.
  void WaitOnSensorErrorEvent(LinuxMockPlatformSensorClient* client) {
    base::RunLoop run_loop;
    EXPECT_CALL(*client, OnSensorError()).WillOnce(Invoke([&]() {
      run_loop.Quit();
    }));
    run_loop.Run();
  }

  // Uses the right task runner to notify SensorDeviceManager that a device has
  // been added.
  void GenerateDeviceAddedEvent() {
    bool success = provider_->blocking_task_runner_->PostTask(
        FROM_HERE,
        base::BindOnce(&MockSensorDeviceManager::DeviceAdded,
                       base::Unretained(mock_sensor_device_manager())));
    ASSERT_TRUE(success);
    // Make sure all tasks have been delivered (including SensorDeviceManager
    // notifying PlatformSensorProviderLinux of a device addition).
    task_environment_.RunUntilIdle();
  }

  // Generates a "remove device" event by removed sensors' directory and
  // notifies the mock service about "removed" event.
  void GenerateDeviceRemovedEvent(const base::FilePath& sensor_dir) {
    {
      base::ScopedAllowBlockingForTesting allow_blocking;
      EXPECT_TRUE(base::DeletePathRecursively(sensor_dir));
    }
    bool success = provider_->blocking_task_runner_->PostTask(
        FROM_HERE,
        base::BindOnce(&MockSensorDeviceManager::DeviceRemoved,
                       base::Unretained(mock_sensor_device_manager())));
    ASSERT_TRUE(success);
    // Make sure all tasks have been delivered (including SensorDeviceManager
    // notifying PlatformSensorProviderLinux of a device removal).
    task_environment_.RunUntilIdle();
  }

  base::test::TaskEnvironment task_environment_;

  std::unique_ptr<PlatformSensorProviderLinux> provider_;

  // Used to simulate the non-test scenario where we're running in an IO thread
  // that forbids blocking operations.
  base::ScopedDisallowBlocking disallow_blocking_;
};

// Tests sensor is not returned if not implemented.
TEST_F(PlatformSensorAndProviderLinuxTest, SensorIsNotImplemented) {
  double sensor_value[kSensorValuesSize] = {5};
  InitializeSupportedSensor(SensorType::AMBIENT_LIGHT, kZero, kZero, kZero,
                            sensor_value);
  SetServiceStart();
  EXPECT_FALSE(CreateSensor(SensorType::PROXIMITY));
}

// Tests sensor is not returned if not supported by hardware.
TEST_F(PlatformSensorAndProviderLinuxTest, SensorIsNotSupported) {
  double sensor_value[kSensorValuesSize] = {5};
  InitializeSupportedSensor(SensorType::AMBIENT_LIGHT, kZero, kZero, kZero,
                            sensor_value);
  SetServiceStart();
  EXPECT_FALSE(CreateSensor(SensorType::ACCELEROMETER));
}

// Tests sensor is returned if supported.
TEST_F(PlatformSensorAndProviderLinuxTest, SensorIsSupported) {
  double sensor_value[kSensorValuesSize] = {5};
  InitializeSupportedSensor(SensorType::AMBIENT_LIGHT, kZero, kZero, kZero,
                            sensor_value);
  SetServiceStart();

  auto sensor = CreateSensor(SensorType::AMBIENT_LIGHT);
  ASSERT_TRUE(sensor);
  EXPECT_EQ(SensorType::AMBIENT_LIGHT, sensor->GetType());
}

// Tests that PlatformSensor::StartListening fails when provided reporting
// frequency is above hardware capabilities.
TEST_F(PlatformSensorAndProviderLinuxTest, StartFails) {
  double sensor_value[kSensorValuesSize] = {5};
  InitializeSupportedSensor(SensorType::AMBIENT_LIGHT, kZero, kZero, kZero,
                            sensor_value);
  SetServiceStart();

  auto sensor = CreateSensor(SensorType::AMBIENT_LIGHT);
  ASSERT_TRUE(sensor);

  auto client =
      std::make_unique<NiceMock<LinuxMockPlatformSensorClient>>(sensor);
  PlatformSensorConfiguration configuration(10);
  EXPECT_FALSE(sensor->StartListening(client.get(), configuration));
}

// Tests that PlatformSensor::StartListening succeeds and notification about
// modified sensor reading is sent to the PlatformSensor::Client interface.
TEST_F(PlatformSensorAndProviderLinuxTest, SensorStarted) {
  double sensor_value[kSensorValuesSize] = {5};
  InitializeSupportedSensor(SensorType::AMBIENT_LIGHT, kZero, kZero, kZero,
                            sensor_value);
  SetServiceStart();

  auto sensor = CreateSensor(SensorType::AMBIENT_LIGHT);
  ASSERT_TRUE(sensor);

  auto client =
      std::make_unique<NiceMock<LinuxMockPlatformSensorClient>>(sensor);
  PlatformSensorConfiguration configuration(5);
  EXPECT_TRUE(sensor->StartListening(client.get(), configuration));
  WaitOnSensorReadingChangedEvent(client.get(), sensor->GetType());
  EXPECT_TRUE(sensor->StopListening(client.get(), configuration));
}

// Tests that OnSensorError is called when sensor is disconnected.
TEST_F(PlatformSensorAndProviderLinuxTest, SensorRemoved) {
  double sensor_value[kSensorValuesSize] = {1};
  InitializeSupportedSensor(SensorType::AMBIENT_LIGHT, kZero, kZero, kZero,
                            sensor_value);
  SetServiceStart();

  auto sensor = CreateSensor(SensorType::AMBIENT_LIGHT);
  ASSERT_TRUE(sensor);

  auto client =
      std::make_unique<NiceMock<LinuxMockPlatformSensorClient>>(sensor);
  PlatformSensorConfiguration configuration(5);
  EXPECT_TRUE(sensor->StartListening(client.get(), configuration));
  GenerateDeviceRemovedEvent(
      mock_sensor_device_manager()->GetSensorsBasePath());
  WaitOnSensorErrorEvent(client.get());
}

// Tests that sensor is not returned if not connected and
// is created after it has been added.
TEST_F(PlatformSensorAndProviderLinuxTest, SensorAddedAndRemoved) {
  double sensor_value[kSensorValuesSize] = {1, 2, 4};
  InitializeSupportedSensor(SensorType::AMBIENT_LIGHT, kZero, kZero, kZero,
                            sensor_value);
  SetServiceStart();

  auto als_sensor = CreateSensor(SensorType::AMBIENT_LIGHT);
  EXPECT_TRUE(als_sensor);
  auto gyro_sensor = CreateSensor(SensorType::GYROSCOPE);
  EXPECT_FALSE(gyro_sensor);

  InitializeSupportedSensor(SensorType::GYROSCOPE, kGyroscopeFrequencyValue,
                            kGyroscopeOffsetValue, kGyroscopeScalingValue,
                            sensor_value);
  GenerateDeviceAddedEvent();
  gyro_sensor = CreateSensor(SensorType::GYROSCOPE);
  EXPECT_TRUE(gyro_sensor);
  EXPECT_EQ(gyro_sensor->GetType(), SensorType::GYROSCOPE);
}

// Checks the main fields of all sensors and initialized right.
TEST_F(PlatformSensorAndProviderLinuxTest, CheckAllSupportedSensors) {
  double sensor_value[kSensorValuesSize] = {1, 2, 3};
  InitializeSupportedSensor(SensorType::AMBIENT_LIGHT, kZero, kZero, kZero,
                            sensor_value);
  InitializeSupportedSensor(
      SensorType::ACCELEROMETER, kAccelerometerFrequencyValue,
      kAccelerometerOffsetValue, kAccelerometerScalingValue, sensor_value);
  InitializeSupportedSensor(SensorType::GYROSCOPE, kGyroscopeFrequencyValue,
                            kGyroscopeOffsetValue, kGyroscopeScalingValue,
                            sensor_value);
  InitializeSupportedSensor(
      SensorType::MAGNETOMETER, kMagnetometerFrequencyValue,
      kMagnetometerOffsetValue, kMagnetometerScalingValue, sensor_value);
  SetServiceStart();

  auto als_sensor = CreateSensor(SensorType::AMBIENT_LIGHT);
  EXPECT_TRUE(als_sensor);
  EXPECT_EQ(als_sensor->GetType(), SensorType::AMBIENT_LIGHT);
  EXPECT_THAT(als_sensor->GetDefaultConfiguration().frequency(),
              SensorTraits<SensorType::AMBIENT_LIGHT>::kDefaultFrequency);

  auto accel_sensor = CreateSensor(SensorType::ACCELEROMETER);
  EXPECT_TRUE(accel_sensor);
  EXPECT_EQ(accel_sensor->GetType(), SensorType::ACCELEROMETER);
  EXPECT_THAT(accel_sensor->GetDefaultConfiguration().frequency(),
              kAccelerometerFrequencyValue);

  auto gyro_sensor = CreateSensor(SensorType::GYROSCOPE);
  EXPECT_TRUE(gyro_sensor);
  EXPECT_EQ(gyro_sensor->GetType(), SensorType::GYROSCOPE);
  EXPECT_THAT(gyro_sensor->GetDefaultConfiguration().frequency(),
              kGyroscopeFrequencyValue);

  auto magn_sensor = CreateSensor(SensorType::MAGNETOMETER);
  EXPECT_TRUE(magn_sensor);
  EXPECT_EQ(magn_sensor->GetType(), SensorType::MAGNETOMETER);
  EXPECT_THAT(magn_sensor->GetDefaultConfiguration().frequency(),
              kMagnetometerFrequencyValue);
}

// Tests that GetMaximumSupportedFrequency provides correct value.
TEST_F(PlatformSensorAndProviderLinuxTest, GetMaximumSupportedFrequency) {
  double sensor_value[kSensorValuesSize] = {5};
  InitializeSupportedSensor(
      SensorType::ACCELEROMETER, kAccelerometerFrequencyValue,
      kAccelerometerOffsetValue, kAccelerometerScalingValue, sensor_value);
  SetServiceStart();

  auto sensor = CreateSensor(SensorType::ACCELEROMETER);
  ASSERT_TRUE(sensor);
  EXPECT_THAT(sensor->GetMaximumSupportedFrequency(),
              kAccelerometerFrequencyValue);
}

// Tests that GetMaximumSupportedFrequency provides correct value when
// OS does not provide any information about frequency.
TEST_F(PlatformSensorAndProviderLinuxTest,
       GetMaximumSupportedFrequencyDefault) {
  double sensor_value[kSensorValuesSize] = {5};
  InitializeSupportedSensor(SensorType::AMBIENT_LIGHT, kZero, kZero, kZero,
                            sensor_value);
  SetServiceStart();

  auto sensor = CreateSensor(SensorType::AMBIENT_LIGHT);
  ASSERT_TRUE(sensor);
  EXPECT_EQ(SensorType::AMBIENT_LIGHT, sensor->GetType());
  EXPECT_THAT(sensor->GetMaximumSupportedFrequency(),
              SensorTraits<SensorType::AMBIENT_LIGHT>::kDefaultFrequency);
}

// Tests that Ambient Light sensor is correctly read.
TEST_F(PlatformSensorAndProviderLinuxTest, CheckAmbientLightReadings) {
  mojo::ScopedSharedBufferHandle handle = provider_->CloneSharedBufferHandle();
  mojo::ScopedSharedBufferMapping mapping = handle->MapAtOffset(
      sizeof(SensorReadingSharedBuffer),
      SensorReadingSharedBuffer::GetOffset(SensorType::AMBIENT_LIGHT));

  double sensor_value[kSensorValuesSize] = {22};
  InitializeSupportedSensor(SensorType::AMBIENT_LIGHT, kZero, kZero, kZero,
                            sensor_value);

  SetServiceStart();

  auto sensor = CreateSensor(SensorType::AMBIENT_LIGHT);
  ASSERT_TRUE(sensor);
  EXPECT_EQ(sensor->GetReportingMode(), mojom::ReportingMode::ON_CHANGE);

  auto client =
      std::make_unique<NiceMock<LinuxMockPlatformSensorClient>>(sensor);
  PlatformSensorConfiguration configuration(
      sensor->GetMaximumSupportedFrequency());
  EXPECT_TRUE(sensor->StartListening(client.get(), configuration));
  WaitOnSensorReadingChangedEvent(client.get(), sensor->GetType());

  SensorReadingSharedBuffer* buffer =
      static_cast<SensorReadingSharedBuffer*>(mapping.get());
  EXPECT_THAT(buffer->reading.als.value, sensor_value[0]);

  EXPECT_TRUE(sensor->StopListening(client.get(), configuration));
}

// Tests that Accelerometer readings are correctly converted.
TEST_F(PlatformSensorAndProviderLinuxTest,
       CheckAccelerometerReadingConversion) {
  mojo::ScopedSharedBufferHandle handle = provider_->CloneSharedBufferHandle();
  mojo::ScopedSharedBufferMapping mapping = handle->MapAtOffset(
      sizeof(SensorReadingSharedBuffer),
      SensorReadingSharedBuffer::GetOffset(SensorType::ACCELEROMETER));

  // As long as WaitOnSensorReadingChangedEvent() waits until client gets a
  // a notification about readings changed, the frequency file must not be
  // created to make the sensor device manager identify this sensor with
  // ON_CHANGE reporting mode. This can be done by sending |kZero| as a
  // frequency value, which means a file is not created.
  // This will allow the LinuxMockPlatformSensorClient to
  // receive a notification and test if reading values are right. Otherwise
  // the test will not know when data is ready.
  double sensor_values[kSensorValuesSize] = {4.5, -2.45, -3.29};
  InitializeSupportedSensor(SensorType::ACCELEROMETER, kZero,
                            kAccelerometerOffsetValue,
                            kAccelerometerScalingValue, sensor_values);

  SetServiceStart();

  auto sensor = CreateSensor(SensorType::ACCELEROMETER);
  ASSERT_TRUE(sensor);
  // The reporting mode is ON_CHANGE only for this test.
  EXPECT_EQ(sensor->GetReportingMode(), mojom::ReportingMode::ON_CHANGE);

  auto client =
      std::make_unique<NiceMock<LinuxMockPlatformSensorClient>>(sensor);
  PlatformSensorConfiguration configuration(10);
  EXPECT_TRUE(sensor->StartListening(client.get(), configuration));
  WaitOnSensorReadingChangedEvent(client.get(), sensor->GetType());

  SensorReadingSharedBuffer* buffer =
      static_cast<SensorReadingSharedBuffer*>(mapping.get());
  double scaling = kAccelerometerScalingValue;
  EXPECT_THAT(buffer->reading.accel.x,
              RoundAccelerometerValue(
                  -scaling * (sensor_values[0] + kAccelerometerOffsetValue)));
  EXPECT_THAT(buffer->reading.accel.y,
              RoundAccelerometerValue(
                  -scaling * (sensor_values[1] + kAccelerometerOffsetValue)));
  EXPECT_THAT(buffer->reading.accel.z,
              RoundAccelerometerValue(
                  -scaling * (sensor_values[2] + kAccelerometerOffsetValue)));

  EXPECT_TRUE(sensor->StopListening(client.get(), configuration));
}

// Tests that LinearAcceleration sensor is not created if its source sensor is
// not available.
TEST_F(PlatformSensorAndProviderLinuxTest,
       CheckLinearAccelerationSensorNotCreatedIfNoAccelerometer) {
  SetServiceStart();

  auto sensor = CreateSensor(SensorType::LINEAR_ACCELERATION);
  EXPECT_FALSE(sensor);
}

// Tests that LinearAcceleration sensor is successfully created and works.
TEST_F(PlatformSensorAndProviderLinuxTest, CheckLinearAcceleration) {
  mojo::ScopedSharedBufferHandle handle = provider_->CloneSharedBufferHandle();
  mojo::ScopedSharedBufferMapping mapping = handle->MapAtOffset(
      sizeof(SensorReadingSharedBuffer),
      SensorReadingSharedBuffer::GetOffset(SensorType::LINEAR_ACCELERATION));
  double sensor_values[kSensorValuesSize] = {0, 0, -base::kMeanGravityDouble};
  InitializeSupportedSensor(SensorType::ACCELEROMETER,
                            kAccelerometerFrequencyValue, kZero, kZero,
                            sensor_values);

  SetServiceStart();

  auto sensor = CreateSensor(SensorType::LINEAR_ACCELERATION);
  ASSERT_TRUE(sensor);
  EXPECT_EQ(sensor->GetReportingMode(), mojom::ReportingMode::CONTINUOUS);

  auto client =
      std::make_unique<NiceMock<LinuxMockPlatformSensorClient>>(sensor);
  PlatformSensorConfiguration configuration(10);
  EXPECT_TRUE(sensor->StartListening(client.get(), configuration));

  // The actual accceration is around 0 but the algorithm needs several
  // iterations to isolate gravity properly.
  int kApproximateExpectedAcceleration = 6;
  WaitOnSensorReadingChangedEvent(client.get(), sensor->GetType());

  SensorReadingSharedBuffer* buffer =
      static_cast<SensorReadingSharedBuffer*>(mapping.get());
  EXPECT_THAT(buffer->reading.accel.x, 0.0);
  EXPECT_THAT(buffer->reading.accel.y, 0.0);
  EXPECT_THAT(static_cast<int>(buffer->reading.accel.z),
              kApproximateExpectedAcceleration);

  EXPECT_TRUE(sensor->StopListening(client.get(), configuration));
}

// Tests that Gyroscope readings are correctly converted.
TEST_F(PlatformSensorAndProviderLinuxTest, CheckGyroscopeReadingConversion) {
  mojo::ScopedSharedBufferHandle handle = provider_->CloneSharedBufferHandle();
  mojo::ScopedSharedBufferMapping mapping = handle->MapAtOffset(
      sizeof(SensorReadingSharedBuffer),
      SensorReadingSharedBuffer::GetOffset(SensorType::GYROSCOPE));

  // As long as WaitOnSensorReadingChangedEvent() waits until client gets a
  // a notification about readings changed, the frequency file must not be
  // created to make the sensor device manager identify this sensor with
  // ON_CHANGE reporting mode. This can be done by sending |kZero| as a
  // frequency value, which means a file is not created.
  // This will allow the LinuxMockPlatformSensorClient to
  // receive a notification and test if reading values are right. Otherwise
  // the test will not know when data is ready.
  double sensor_values[kSensorValuesSize] = {2.2, -3.8, -108.7};
  InitializeSupportedSensor(SensorType::GYROSCOPE, kZero, kGyroscopeOffsetValue,
                            kGyroscopeScalingValue, sensor_values);

  SetServiceStart();

  auto sensor = CreateSensor(SensorType::GYROSCOPE);
  ASSERT_TRUE(sensor);
  // The reporting mode is ON_CHANGE only for this test.
  EXPECT_EQ(sensor->GetReportingMode(), mojom::ReportingMode::ON_CHANGE);

  auto client =
      std::make_unique<NiceMock<LinuxMockPlatformSensorClient>>(sensor);
  PlatformSensorConfiguration configuration(10);
  EXPECT_TRUE(sensor->StartListening(client.get(), configuration));
  WaitOnSensorReadingChangedEvent(client.get(), sensor->GetType());

  SensorReadingSharedBuffer* buffer =
      static_cast<SensorReadingSharedBuffer*>(mapping.get());
  double scaling = kGyroscopeScalingValue;
  EXPECT_THAT(buffer->reading.gyro.x,
              RoundGyroscopeValue(scaling *
                                  (sensor_values[0] + kGyroscopeOffsetValue)));
  EXPECT_THAT(buffer->reading.gyro.y,
              RoundGyroscopeValue(scaling *
                                  (sensor_values[1] + kGyroscopeOffsetValue)));
  EXPECT_THAT(buffer->reading.gyro.z,
              RoundGyroscopeValue(scaling *
                                  (sensor_values[2] + kGyroscopeOffsetValue)));

  EXPECT_TRUE(sensor->StopListening(client.get(), configuration));
}

// Tests that Magnetometer readings are correctly converted.
TEST_F(PlatformSensorAndProviderLinuxTest, CheckMagnetometerReadingConversion) {
  mojo::ScopedSharedBufferHandle handle = provider_->CloneSharedBufferHandle();
  mojo::ScopedSharedBufferMapping mapping = handle->MapAtOffset(
      sizeof(SensorReadingSharedBuffer),
      SensorReadingSharedBuffer::GetOffset(SensorType::MAGNETOMETER));

  // As long as WaitOnSensorReadingChangedEvent() waits until client gets a
  // a notification about readings changed, the frequency file must not be
  // created to make the sensor device manager identify this sensor with
  // ON_CHANGE reporting mode. This can be done by sending |kZero| as a
  // frequency value, which means a file is not created.
  // This will allow the LinuxMockPlatformSensorClient to
  // receive a notification and test if reading values are right. Otherwise
  // the test will not know when data is ready.
  double sensor_values[kSensorValuesSize] = {2.2, -3.8, -108.7};
  InitializeSupportedSensor(SensorType::MAGNETOMETER, kZero,
                            kMagnetometerOffsetValue, kMagnetometerScalingValue,
                            sensor_values);

  SetServiceStart();

  auto sensor = CreateSensor(SensorType::MAGNETOMETER);
  ASSERT_TRUE(sensor);
  // The reporting mode is ON_CHANGE only for this test.
  EXPECT_EQ(sensor->GetReportingMode(), mojom::ReportingMode::ON_CHANGE);

  auto client =
      std::make_unique<NiceMock<LinuxMockPlatformSensorClient>>(sensor);
  PlatformSensorConfiguration configuration(10);
  EXPECT_TRUE(sensor->StartListening(client.get(), configuration));
  WaitOnSensorReadingChangedEvent(client.get(), sensor->GetType());

  SensorReadingSharedBuffer* buffer =
      static_cast<SensorReadingSharedBuffer*>(mapping.get());
  double scaling = kMagnetometerScalingValue * kMicroteslaInGauss;
  EXPECT_THAT(buffer->reading.magn.x,
              scaling * (sensor_values[0] + kMagnetometerOffsetValue));
  EXPECT_THAT(buffer->reading.magn.y,
              scaling * (sensor_values[1] + kMagnetometerOffsetValue));
  EXPECT_THAT(buffer->reading.magn.z,
              scaling * (sensor_values[2] + kMagnetometerOffsetValue));

  EXPECT_TRUE(sensor->StopListening(client.get(), configuration));
}

// Tests that Ambient Light sensor client's OnSensorReadingChanged() is called
// when the Ambient Light sensor's reporting mode is
// mojom::ReportingMode::CONTINUOUS.
TEST_F(PlatformSensorAndProviderLinuxTest,
       SensorClientGetReadingChangedNotificationWhenSensorIsInContinuousMode) {
  mojo::ScopedSharedBufferHandle handle = provider_->CloneSharedBufferHandle();
  mojo::ScopedSharedBufferMapping mapping = handle->MapAtOffset(
      sizeof(SensorReadingSharedBuffer),
      SensorReadingSharedBuffer::GetOffset(SensorType::AMBIENT_LIGHT));

  double sensor_value[kSensorValuesSize] = {22};
  // Set a non-zero frequency here and sensor's reporting mode will be
  // mojom::ReportingMode::CONTINUOUS.
  InitializeSupportedSensor(SensorType::AMBIENT_LIGHT,
                            kAmbientLightFrequencyValue, kZero, kZero,
                            sensor_value);

  SetServiceStart();

  auto sensor = CreateSensor(SensorType::AMBIENT_LIGHT);
  ASSERT_TRUE(sensor);
  EXPECT_EQ(mojom::ReportingMode::CONTINUOUS, sensor->GetReportingMode());

  auto client =
      std::make_unique<NiceMock<LinuxMockPlatformSensorClient>>(sensor);

  PlatformSensorConfiguration configuration(
      sensor->GetMaximumSupportedFrequency());
  EXPECT_TRUE(sensor->StartListening(client.get(), configuration));

  WaitOnSensorReadingChangedEvent(client.get(), sensor->GetType());

  SensorReadingSharedBuffer* buffer =
      static_cast<SensorReadingSharedBuffer*>(mapping.get());
  EXPECT_THAT(buffer->reading.als.value, sensor_value[0]);

  EXPECT_TRUE(sensor->StopListening(client.get(), configuration));
}

// Tests that ABSOLUTE_ORIENTATION_EULER_ANGLES/ABSOLUTE_ORIENTATION_QUATERNION
// sensor is not created if both of its source sensors are not available.
TEST_F(
    PlatformSensorAndProviderLinuxTest,
    CheckAbsoluteOrientationSensorNotCreatedIfNoAccelerometerAndNoMagnetometer) {
  SetServiceStart();

  {
    auto sensor = CreateSensor(SensorType::ABSOLUTE_ORIENTATION_EULER_ANGLES);
    EXPECT_FALSE(sensor);
  }

  {
    auto sensor = CreateSensor(SensorType::ABSOLUTE_ORIENTATION_QUATERNION);
    EXPECT_FALSE(sensor);
  }
}

// Tests that ABSOLUTE_ORIENTATION_EULER_ANGLES/ABSOLUTE_ORIENTATION_QUATERNION
// sensor is not created if accelerometer is not available.
TEST_F(PlatformSensorAndProviderLinuxTest,
       CheckAbsoluteOrientationSensorNotCreatedIfNoAccelerometer) {
  double sensor_value[kSensorValuesSize] = {1, 2, 3};
  InitializeSupportedSensor(
      SensorType::MAGNETOMETER, kMagnetometerFrequencyValue,
      kMagnetometerOffsetValue, kMagnetometerScalingValue, sensor_value);
  SetServiceStart();

  {
    auto sensor = CreateSensor(SensorType::ABSOLUTE_ORIENTATION_EULER_ANGLES);
    EXPECT_FALSE(sensor);
  }

  {
    auto sensor = CreateSensor(SensorType::ABSOLUTE_ORIENTATION_QUATERNION);
    EXPECT_FALSE(sensor);
  }
}

// Tests that ABSOLUTE_ORIENTATION_EULER_ANGLES/ABSOLUTE_ORIENTATION_QUATERNION
// sensor is not created if magnetometer is not available.
TEST_F(PlatformSensorAndProviderLinuxTest,
       CheckAbsoluteOrientationSensorNotCreatedIfNoMagnetometer) {
  double sensor_value[kSensorValuesSize] = {1, 2, 3};
  InitializeSupportedSensor(
      SensorType::ACCELEROMETER, kAccelerometerFrequencyValue,
      kAccelerometerOffsetValue, kAccelerometerScalingValue, sensor_value);
  SetServiceStart();

  {
    auto sensor = CreateSensor(SensorType::ABSOLUTE_ORIENTATION_EULER_ANGLES);
    EXPECT_FALSE(sensor);
  }

  {
    auto sensor = CreateSensor(SensorType::ABSOLUTE_ORIENTATION_QUATERNION);
    EXPECT_FALSE(sensor);
  }
}

// Tests that ABSOLUTE_ORIENTATION_EULER_ANGLES sensor is successfully created.
TEST_F(PlatformSensorAndProviderLinuxTest,
       CheckAbsoluteOrientationEulerAnglesSensor) {
  double sensor_value[kSensorValuesSize] = {1, 2, 3};
  InitializeSupportedSensor(
      SensorType::ACCELEROMETER, kAccelerometerFrequencyValue,
      kAccelerometerOffsetValue, kAccelerometerScalingValue, sensor_value);
  InitializeSupportedSensor(
      SensorType::MAGNETOMETER, kMagnetometerFrequencyValue,
      kMagnetometerOffsetValue, kMagnetometerScalingValue, sensor_value);
  SetServiceStart();

  auto sensor = CreateSensor(SensorType::ABSOLUTE_ORIENTATION_EULER_ANGLES);
  EXPECT_TRUE(sensor);
}

// Tests that ABSOLUTE_ORIENTATION_QUATERNION sensor is successfully created.
TEST_F(PlatformSensorAndProviderLinuxTest,
       CheckAbsoluteOrientationQuaternionSensor) {
  double sensor_value[kSensorValuesSize] = {1, 2, 3};
  InitializeSupportedSensor(
      SensorType::ACCELEROMETER, kAccelerometerFrequencyValue,
      kAccelerometerOffsetValue, kAccelerometerScalingValue, sensor_value);
  InitializeSupportedSensor(
      SensorType::MAGNETOMETER, kMagnetometerFrequencyValue,
      kMagnetometerOffsetValue, kMagnetometerScalingValue, sensor_value);
  SetServiceStart();

  auto sensor = CreateSensor(SensorType::ABSOLUTE_ORIENTATION_QUATERNION);
  EXPECT_TRUE(sensor);
}

// Tests that RELATIVE_ORIENTATION_EULER_ANGLES/RELATIVE_ORIENTATION_QUATERNION
// sensor is not created if both accelerometer and gyroscope are not available.
TEST_F(
    PlatformSensorAndProviderLinuxTest,
    CheckRelativeOrientationSensorNotCreatedIfNoAccelerometerAndNoGyroscope) {
  SetServiceStart();

  {
    auto sensor = CreateSensor(SensorType::RELATIVE_ORIENTATION_EULER_ANGLES);
    EXPECT_FALSE(sensor);
  }

  {
    auto sensor = CreateSensor(SensorType::RELATIVE_ORIENTATION_QUATERNION);
    EXPECT_FALSE(sensor);
  }
}

// Tests that RELATIVE_ORIENTATION_EULER_ANGLES/RELATIVE_ORIENTATION_QUATERNION
// sensor is not created if accelerometer is not available.
TEST_F(PlatformSensorAndProviderLinuxTest,
       CheckRelativeOrientationSensorNotCreatedIfNoAccelerometer) {
  double sensor_value[kSensorValuesSize] = {1, 2, 3};
  InitializeSupportedSensor(SensorType::GYROSCOPE, kGyroscopeFrequencyValue,
                            kGyroscopeOffsetValue, kGyroscopeScalingValue,
                            sensor_value);
  SetServiceStart();

  {
    auto sensor = CreateSensor(SensorType::RELATIVE_ORIENTATION_EULER_ANGLES);
    EXPECT_FALSE(sensor);
  }

  {
    auto sensor = CreateSensor(SensorType::RELATIVE_ORIENTATION_QUATERNION);
    EXPECT_FALSE(sensor);
  }
}

// Tests that RELATIVE_ORIENTATION_EULER_ANGLES sensor is successfully created
// if both accelerometer and gyroscope are available.
TEST_F(
    PlatformSensorAndProviderLinuxTest,
    CheckRelativeOrientationEulerAnglesSensorUsingAccelerometerAndGyroscope) {
  double sensor_value[kSensorValuesSize] = {1, 2, 3};
  InitializeSupportedSensor(SensorType::GYROSCOPE, kGyroscopeFrequencyValue,
                            kGyroscopeOffsetValue, kGyroscopeScalingValue,
                            sensor_value);
  InitializeSupportedSensor(
      SensorType::ACCELEROMETER, kAccelerometerFrequencyValue,
      kAccelerometerOffsetValue, kAccelerometerScalingValue, sensor_value);
  SetServiceStart();

  auto sensor = CreateSensor(SensorType::RELATIVE_ORIENTATION_EULER_ANGLES);
  EXPECT_TRUE(sensor);
}

// Tests that RELATIVE_ORIENTATION_EULER_ANGLES sensor is successfully created
// if only accelerometer is available.
TEST_F(PlatformSensorAndProviderLinuxTest,
       CheckRelativeOrientationEulerAnglesSensorUsingAccelerometer) {
  double sensor_value[kSensorValuesSize] = {1, 2, 3};
  InitializeSupportedSensor(
      SensorType::ACCELEROMETER, kAccelerometerFrequencyValue,
      kAccelerometerOffsetValue, kAccelerometerScalingValue, sensor_value);
  SetServiceStart();

  auto sensor = CreateSensor(SensorType::RELATIVE_ORIENTATION_EULER_ANGLES);
  EXPECT_TRUE(sensor);
}

// Tests that RELATIVE_ORIENTATION_QUATERNION sensor is successfully created if
// both accelerometer and gyroscope are available.
TEST_F(PlatformSensorAndProviderLinuxTest,
       CheckRelativeOrientationQuaternionSensorUsingAccelerometerAndGyroscope) {
  double sensor_value[kSensorValuesSize] = {1, 2, 3};
  InitializeSupportedSensor(SensorType::GYROSCOPE, kGyroscopeFrequencyValue,
                            kGyroscopeOffsetValue, kGyroscopeScalingValue,
                            sensor_value);
  InitializeSupportedSensor(
      SensorType::ACCELEROMETER, kAccelerometerFrequencyValue,
      kAccelerometerOffsetValue, kAccelerometerScalingValue, sensor_value);
  SetServiceStart();

  auto sensor = CreateSensor(SensorType::RELATIVE_ORIENTATION_QUATERNION);
  EXPECT_TRUE(sensor);
}

// Tests that RELATIVE_ORIENTATION_QUATERNION sensor is successfully created if
// only accelerometer is available.
TEST_F(PlatformSensorAndProviderLinuxTest,
       CheckRelativeOrientationQuaternionSensorUsingAccelerometer) {
  double sensor_value[kSensorValuesSize] = {1, 2, 3};
  InitializeSupportedSensor(
      SensorType::ACCELEROMETER, kAccelerometerFrequencyValue,
      kAccelerometerOffsetValue, kAccelerometerScalingValue, sensor_value);
  SetServiceStart();

  auto sensor = CreateSensor(SensorType::RELATIVE_ORIENTATION_QUATERNION);
  EXPECT_TRUE(sensor);
}

}  // namespace device