blob: 3f60741e47eb123c8a0b8a0d26fec13809513a44 [file] [log] [blame]
Mathias Agopian589ce852010-07-13 22:21:56 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_GUI_SENSOR_H
18#define ANDROID_GUI_SENSOR_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
23#include <utils/Errors.h>
Mathias Agopian589ce852010-07-13 22:21:56 -070024#include <utils/Flattenable.h>
Mathias Agopianb62013f2011-05-17 22:54:42 -070025#include <utils/String8.h>
26#include <utils/Timers.h>
Mathias Agopian589ce852010-07-13 22:21:56 -070027
28#include <hardware/sensors.h>
29
30#include <android/sensor.h>
31
32// ----------------------------------------------------------------------------
33// Concrete types for the NDK
34struct ASensor { };
35
36// ----------------------------------------------------------------------------
37namespace android {
38// ----------------------------------------------------------------------------
39
40class Parcel;
41
42// ----------------------------------------------------------------------------
43
Mathias Agopian8683fca2012-08-12 19:37:16 -070044class Sensor : public ASensor, public LightFlattenable<Sensor>
Mathias Agopian589ce852010-07-13 22:21:56 -070045{
46public:
47 enum {
48 TYPE_ACCELEROMETER = ASENSOR_TYPE_ACCELEROMETER,
49 TYPE_MAGNETIC_FIELD = ASENSOR_TYPE_MAGNETIC_FIELD,
50 TYPE_GYROSCOPE = ASENSOR_TYPE_GYROSCOPE,
51 TYPE_LIGHT = ASENSOR_TYPE_LIGHT,
52 TYPE_PROXIMITY = ASENSOR_TYPE_PROXIMITY
53 };
54
Peng Xu6a2d3a02015-12-21 12:00:23 -080055 struct uuid_t{
56 union {
57 uint8_t b[16];
58 int64_t i64[2];
59 };
60 uuid_t(const uint8_t (&uuid)[16]) { memcpy(b, uuid, sizeof(b));}
61 uuid_t() : b{0} {}
62 };
Peng Xu2576cb62016-01-20 00:22:09 -080063
Peng Xu0cc8f802016-04-05 23:46:03 -070064 Sensor(const char * name = "");
Peng Xu2576cb62016-01-20 00:22:09 -080065 Sensor(struct sensor_t const* hwSensor, int halVersion = 0);
Peng Xu6a2d3a02015-12-21 12:00:23 -080066 Sensor(struct sensor_t const& hwSensor, const uuid_t& uuid, int halVersion = 0);
Peng Xu2576cb62016-01-20 00:22:09 -080067 ~Sensor();
Mathias Agopian589ce852010-07-13 22:21:56 -070068
69 const String8& getName() const;
70 const String8& getVendor() const;
71 int32_t getHandle() const;
72 int32_t getType() const;
73 float getMinValue() const;
74 float getMaxValue() const;
75 float getResolution() const;
76 float getPowerUsage() const;
Mathias Agopiana48bcf62010-07-29 16:51:38 -070077 int32_t getMinDelay() const;
Mathias Agopianb62013f2011-05-17 22:54:42 -070078 nsecs_t getMinDelayNs() const;
79 int32_t getVersion() const;
Dan Stozad723bd72014-11-18 10:24:03 -080080 uint32_t getFifoReservedEventCount() const;
81 uint32_t getFifoMaxEventCount() const;
Aravind Akella70018042014-04-07 22:52:37 +000082 const String8& getStringType() const;
83 const String8& getRequiredPermission() const;
Svetoslavb412f6e2015-04-29 16:50:41 -070084 bool isRequiredPermissionRuntime() const;
85 int32_t getRequiredAppOp() const;
Aravind Akellad9441e42014-05-13 18:20:30 -070086 int32_t getMaxDelay() const;
Dan Stozad723bd72014-11-18 10:24:03 -080087 uint32_t getFlags() const;
Aravind Akella9a844cf2014-02-11 18:58:52 -080088 bool isWakeUpSensor() const;
Peng Xu0cc8f802016-04-05 23:46:03 -070089 bool isDynamicSensor() const;
Peng Xu6a2d3a02015-12-21 12:00:23 -080090 bool hasAdditionalInfo() const;
Aravind Akella0e025c52014-06-03 19:19:57 -070091 int32_t getReportingMode() const;
Peng Xu2576cb62016-01-20 00:22:09 -080092 const uuid_t& getUuid() const;
Mathias Agopian589ce852010-07-13 22:21:56 -070093
Mathias Agopian8683fca2012-08-12 19:37:16 -070094 // LightFlattenable protocol
95 inline bool isFixedSize() const { return false; }
Mathias Agopiane1424282013-07-29 21:24:40 -070096 size_t getFlattenedSize() const;
97 status_t flatten(void* buffer, size_t size) const;
Mathias Agopian8683fca2012-08-12 19:37:16 -070098 status_t unflatten(void const* buffer, size_t size);
Mathias Agopian589ce852010-07-13 22:21:56 -070099
100private:
101 String8 mName;
102 String8 mVendor;
103 int32_t mHandle;
104 int32_t mType;
105 float mMinValue;
106 float mMaxValue;
107 float mResolution;
108 float mPower;
Mathias Agopiana48bcf62010-07-29 16:51:38 -0700109 int32_t mMinDelay;
Mathias Agopianb62013f2011-05-17 22:54:42 -0700110 int32_t mVersion;
Dan Stozad723bd72014-11-18 10:24:03 -0800111 uint32_t mFifoReservedEventCount;
112 uint32_t mFifoMaxEventCount;
Aravind Akella70018042014-04-07 22:52:37 +0000113 String8 mStringType;
114 String8 mRequiredPermission;
Svetoslavb412f6e2015-04-29 16:50:41 -0700115 bool mRequiredPermissionRuntime = false;
116 int32_t mRequiredAppOp;
Aravind Akellad9441e42014-05-13 18:20:30 -0700117 int32_t mMaxDelay;
Dan Stozaf10c46e2014-11-11 10:32:31 -0800118 uint32_t mFlags;
Peng Xu2576cb62016-01-20 00:22:09 -0800119 uuid_t mUuid;
Aravind Akella70018042014-04-07 22:52:37 +0000120 static void flattenString8(void*& buffer, size_t& size, const String8& string8);
121 static bool unflattenString8(void const*& buffer, size_t& size, String8& outputString8);
Mathias Agopian589ce852010-07-13 22:21:56 -0700122};
123
124// ----------------------------------------------------------------------------
125}; // namespace android
126
127#endif // ANDROID_GUI_SENSOR_H