| Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 1 | /* | 
 | 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 Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 24 | #include <utils/Flattenable.h> | 
| Mathias Agopian | b62013f | 2011-05-17 22:54:42 -0700 | [diff] [blame] | 25 | #include <utils/String8.h> | 
 | 26 | #include <utils/Timers.h> | 
| Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 27 |  | 
 | 28 | #include <hardware/sensors.h> | 
 | 29 |  | 
 | 30 | #include <android/sensor.h> | 
 | 31 |  | 
 | 32 | // ---------------------------------------------------------------------------- | 
 | 33 | // Concrete types for the NDK | 
 | 34 | struct ASensor { }; | 
 | 35 |  | 
 | 36 | // ---------------------------------------------------------------------------- | 
 | 37 | namespace android { | 
 | 38 | // ---------------------------------------------------------------------------- | 
 | 39 |  | 
 | 40 | class Parcel; | 
 | 41 |  | 
 | 42 | // ---------------------------------------------------------------------------- | 
 | 43 |  | 
| Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 44 | class Sensor : public ASensor, public LightFlattenable<Sensor> | 
| Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 45 | { | 
 | 46 | public: | 
 | 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 Xu | 6a2d3a0 | 2015-12-21 12:00:23 -0800 | [diff] [blame] | 55 |     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 Xu | 2576cb6 | 2016-01-20 00:22:09 -0800 | [diff] [blame] | 63 |  | 
| Colin Cross | 3175c09 | 2016-09-26 18:11:41 -0700 | [diff] [blame] | 64 |     Sensor(const Sensor&) = default; | 
 | 65 |     Sensor& operator=(const Sensor&) = default; | 
 | 66 |  | 
| Peng Xu | 0cc8f80 | 2016-04-05 23:46:03 -0700 | [diff] [blame] | 67 |     Sensor(const char * name = ""); | 
| Peng Xu | 2576cb6 | 2016-01-20 00:22:09 -0800 | [diff] [blame] | 68 |     Sensor(struct sensor_t const* hwSensor, int halVersion = 0); | 
| Peng Xu | 6a2d3a0 | 2015-12-21 12:00:23 -0800 | [diff] [blame] | 69 |     Sensor(struct sensor_t const& hwSensor, const uuid_t& uuid, int halVersion = 0); | 
| Peng Xu | 2576cb6 | 2016-01-20 00:22:09 -0800 | [diff] [blame] | 70 |     ~Sensor(); | 
| Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 71 |  | 
 | 72 |     const String8& getName() const; | 
 | 73 |     const String8& getVendor() const; | 
 | 74 |     int32_t getHandle() const; | 
 | 75 |     int32_t getType() const; | 
 | 76 |     float getMinValue() const; | 
 | 77 |     float getMaxValue() const; | 
 | 78 |     float getResolution() const; | 
 | 79 |     float getPowerUsage() const; | 
| Mathias Agopian | a48bcf6 | 2010-07-29 16:51:38 -0700 | [diff] [blame] | 80 |     int32_t getMinDelay() const; | 
| Mathias Agopian | b62013f | 2011-05-17 22:54:42 -0700 | [diff] [blame] | 81 |     nsecs_t getMinDelayNs() const; | 
 | 82 |     int32_t getVersion() const; | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 83 |     uint32_t getFifoReservedEventCount() const; | 
 | 84 |     uint32_t getFifoMaxEventCount() const; | 
| Aravind Akella | 7001804 | 2014-04-07 22:52:37 +0000 | [diff] [blame] | 85 |     const String8& getStringType() const; | 
 | 86 |     const String8& getRequiredPermission() const; | 
| Svetoslav | b412f6e | 2015-04-29 16:50:41 -0700 | [diff] [blame] | 87 |     bool isRequiredPermissionRuntime() const; | 
 | 88 |     int32_t getRequiredAppOp() const; | 
| Aravind Akella | d9441e4 | 2014-05-13 18:20:30 -0700 | [diff] [blame] | 89 |     int32_t getMaxDelay() const; | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 90 |     uint32_t getFlags() const; | 
| Aravind Akella | 9a844cf | 2014-02-11 18:58:52 -0800 | [diff] [blame] | 91 |     bool isWakeUpSensor() const; | 
| Peng Xu | 0cc8f80 | 2016-04-05 23:46:03 -0700 | [diff] [blame] | 92 |     bool isDynamicSensor() const; | 
| Peng Xu | 6a2d3a0 | 2015-12-21 12:00:23 -0800 | [diff] [blame] | 93 |     bool hasAdditionalInfo() const; | 
| Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 94 |     int32_t getReportingMode() const; | 
| Greg Kaiser | 53ca2e0 | 2016-06-21 16:11:14 -0700 | [diff] [blame] | 95 |  | 
 | 96 |     // Note that after setId() has been called, getUuid() no longer | 
 | 97 |     // returns the UUID. | 
 | 98 |     // TODO(b/29547335): Remove getUuid(), add getUuidIndex(), and | 
 | 99 |     //     make sure setId() doesn't change the UuidIndex. | 
| Peng Xu | 2576cb6 | 2016-01-20 00:22:09 -0800 | [diff] [blame] | 100 |     const uuid_t& getUuid() const; | 
| Greg Kaiser | 53ca2e0 | 2016-06-21 16:11:14 -0700 | [diff] [blame] | 101 |     int32_t getId() const; | 
 | 102 |     void setId(int32_t id); | 
| Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 103 |  | 
| Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 104 |     // LightFlattenable protocol | 
 | 105 |     inline bool isFixedSize() const { return false; } | 
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 106 |     size_t getFlattenedSize() const; | 
 | 107 |     status_t flatten(void* buffer, size_t size) const; | 
| Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 108 |     status_t unflatten(void const* buffer, size_t size); | 
| Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 109 |  | 
 | 110 | private: | 
 | 111 |     String8 mName; | 
 | 112 |     String8 mVendor; | 
 | 113 |     int32_t mHandle; | 
 | 114 |     int32_t mType; | 
 | 115 |     float   mMinValue; | 
 | 116 |     float   mMaxValue; | 
 | 117 |     float   mResolution; | 
 | 118 |     float   mPower; | 
| Mathias Agopian | a48bcf6 | 2010-07-29 16:51:38 -0700 | [diff] [blame] | 119 |     int32_t mMinDelay; | 
| Mathias Agopian | b62013f | 2011-05-17 22:54:42 -0700 | [diff] [blame] | 120 |     int32_t mVersion; | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 121 |     uint32_t mFifoReservedEventCount; | 
 | 122 |     uint32_t mFifoMaxEventCount; | 
| Aravind Akella | 7001804 | 2014-04-07 22:52:37 +0000 | [diff] [blame] | 123 |     String8 mStringType; | 
 | 124 |     String8 mRequiredPermission; | 
| Svetoslav | b412f6e | 2015-04-29 16:50:41 -0700 | [diff] [blame] | 125 |     bool mRequiredPermissionRuntime = false; | 
 | 126 |     int32_t mRequiredAppOp; | 
| Aravind Akella | d9441e4 | 2014-05-13 18:20:30 -0700 | [diff] [blame] | 127 |     int32_t mMaxDelay; | 
| Dan Stoza | f10c46e | 2014-11-11 10:32:31 -0800 | [diff] [blame] | 128 |     uint32_t mFlags; | 
| Greg Kaiser | 53ca2e0 | 2016-06-21 16:11:14 -0700 | [diff] [blame] | 129 |     // TODO(b/29547335): Get rid of this field and replace with an index. | 
 | 130 |     //     The index will be into a separate global vector of UUIDs. | 
 | 131 |     //     Also add an mId field (and change flatten/unflatten appropriately). | 
| Peng Xu | 2576cb6 | 2016-01-20 00:22:09 -0800 | [diff] [blame] | 132 |     uuid_t  mUuid; | 
| Aravind Akella | 7001804 | 2014-04-07 22:52:37 +0000 | [diff] [blame] | 133 |     static void flattenString8(void*& buffer, size_t& size, const String8& string8); | 
 | 134 |     static bool unflattenString8(void const*& buffer, size_t& size, String8& outputString8); | 
| Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 135 | }; | 
 | 136 |  | 
 | 137 | // ---------------------------------------------------------------------------- | 
 | 138 | }; // namespace android | 
 | 139 |  | 
 | 140 | #endif // ANDROID_GUI_SENSOR_H |