Sensor.h revision e36e34731cbe77a49aa5e7d687dde041d83d0370
1589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian/*
2589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian * Copyright (C) 2010 The Android Open Source Project
3589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian *
4589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian * Licensed under the Apache License, Version 2.0 (the "License");
5589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian * you may not use this file except in compliance with the License.
6589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian * You may obtain a copy of the License at
7589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian *
8589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian *      http://www.apache.org/licenses/LICENSE-2.0
9589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian *
10589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian * Unless required by applicable law or agreed to in writing, software
11589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian * distributed under the License is distributed on an "AS IS" BASIS,
12589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian * See the License for the specific language governing permissions and
14589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian * limitations under the License.
15589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian */
16589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
17589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#ifndef ANDROID_GUI_SENSOR_H
18589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#define ANDROID_GUI_SENSOR_H
19589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
20589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#include <stdint.h>
21589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#include <sys/types.h>
22589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
23589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#include <utils/Errors.h>
24589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#include <utils/Flattenable.h>
25b62013f6aafee08cfad25a2712dc32264e44f783Mathias Agopian#include <utils/String8.h>
26b62013f6aafee08cfad25a2712dc32264e44f783Mathias Agopian#include <utils/Timers.h>
27589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
28589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#include <hardware/sensors.h>
29589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
30589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#include <android/sensor.h>
31589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
32589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian// ----------------------------------------------------------------------------
33589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian// Concrete types for the NDK
34589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopianstruct ASensor { };
35589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
36589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian// ----------------------------------------------------------------------------
37589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopiannamespace android {
38589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian// ----------------------------------------------------------------------------
39589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
40589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopianclass Parcel;
41589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
42589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian// ----------------------------------------------------------------------------
43589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
448683fca395d01734ec7946e9f0595ec5d7b754c6Mathias Agopianclass Sensor : public ASensor, public LightFlattenable<Sensor>
45589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian{
46589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopianpublic:
47589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    enum {
48589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian        TYPE_ACCELEROMETER  = ASENSOR_TYPE_ACCELEROMETER,
49589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian        TYPE_MAGNETIC_FIELD = ASENSOR_TYPE_MAGNETIC_FIELD,
50589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian        TYPE_GYROSCOPE      = ASENSOR_TYPE_GYROSCOPE,
51589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian        TYPE_LIGHT          = ASENSOR_TYPE_LIGHT,
52589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian        TYPE_PROXIMITY      = ASENSOR_TYPE_PROXIMITY
53589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    };
54589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
556a2d3a06caa337857cf60cfc70a9a78909ad3608Peng Xu    struct uuid_t{
566a2d3a06caa337857cf60cfc70a9a78909ad3608Peng Xu        union {
576a2d3a06caa337857cf60cfc70a9a78909ad3608Peng Xu            uint8_t b[16];
586a2d3a06caa337857cf60cfc70a9a78909ad3608Peng Xu            int64_t i64[2];
596a2d3a06caa337857cf60cfc70a9a78909ad3608Peng Xu        };
606a2d3a06caa337857cf60cfc70a9a78909ad3608Peng Xu        uuid_t(const uint8_t (&uuid)[16]) { memcpy(b, uuid, sizeof(b));}
616a2d3a06caa337857cf60cfc70a9a78909ad3608Peng Xu        uuid_t() : b{0} {}
626a2d3a06caa337857cf60cfc70a9a78909ad3608Peng Xu    };
632576cb63b3fe1592f54816625036566b9eb0793aPeng Xu
643175c094d782822f6b7aaf31a8593150b5c48b41Colin Cross    Sensor(const Sensor&) = default;
653175c094d782822f6b7aaf31a8593150b5c48b41Colin Cross    Sensor& operator=(const Sensor&) = default;
663175c094d782822f6b7aaf31a8593150b5c48b41Colin Cross
670cc8f809924706c7d683da30605f432635dd5bb6Peng Xu    Sensor(const char * name = "");
682576cb63b3fe1592f54816625036566b9eb0793aPeng Xu    Sensor(struct sensor_t const* hwSensor, int halVersion = 0);
696a2d3a06caa337857cf60cfc70a9a78909ad3608Peng Xu    Sensor(struct sensor_t const& hwSensor, const uuid_t& uuid, int halVersion = 0);
702576cb63b3fe1592f54816625036566b9eb0793aPeng Xu    ~Sensor();
71589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
72589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    const String8& getName() const;
73589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    const String8& getVendor() const;
74589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    int32_t getHandle() const;
75589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    int32_t getType() const;
76589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    float getMinValue() const;
77589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    float getMaxValue() const;
78589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    float getResolution() const;
79589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    float getPowerUsage() const;
80a48bcf62b6a26f24a0bdd2b44bb39fadce499e92Mathias Agopian    int32_t getMinDelay() const;
81b62013f6aafee08cfad25a2712dc32264e44f783Mathias Agopian    nsecs_t getMinDelayNs() const;
82b62013f6aafee08cfad25a2712dc32264e44f783Mathias Agopian    int32_t getVersion() const;
83d723bd7669b4fc88dc282d8bf8ba5ecb2849d22fDan Stoza    uint32_t getFifoReservedEventCount() const;
84d723bd7669b4fc88dc282d8bf8ba5ecb2849d22fDan Stoza    uint32_t getFifoMaxEventCount() const;
85700180487ffec09d9df1657b018a7caadac24b75Aravind Akella    const String8& getStringType() const;
86700180487ffec09d9df1657b018a7caadac24b75Aravind Akella    const String8& getRequiredPermission() const;
87b412f6e203b38f8047f760261a5e3dc6d0722f08Svetoslav    bool isRequiredPermissionRuntime() const;
88b412f6e203b38f8047f760261a5e3dc6d0722f08Svetoslav    int32_t getRequiredAppOp() const;
89d9441e4c27bb7d0b1dfe2a8b5c1ee1714442648dAravind Akella    int32_t getMaxDelay() const;
90d723bd7669b4fc88dc282d8bf8ba5ecb2849d22fDan Stoza    uint32_t getFlags() const;
919a844cf78f09953145200b4074d47589257a408cAravind Akella    bool isWakeUpSensor() const;
920cc8f809924706c7d683da30605f432635dd5bb6Peng Xu    bool isDynamicSensor() const;
936a2d3a06caa337857cf60cfc70a9a78909ad3608Peng Xu    bool hasAdditionalInfo() const;
94e36e34731cbe77a49aa5e7d687dde041d83d0370Peng Xu    int32_t getHighestDirectReportRateLevel() const;
95e36e34731cbe77a49aa5e7d687dde041d83d0370Peng Xu    bool isDirectChannelTypeSupported(int32_t sharedMemType) const;
960e025c5af365e45e02cb75c1d46b46c7f4cd44cbAravind Akella    int32_t getReportingMode() const;
9753ca2e00c6f2a71b93c8e3c8e85aeeb03c5bd06dGreg Kaiser
9853ca2e00c6f2a71b93c8e3c8e85aeeb03c5bd06dGreg Kaiser    // Note that after setId() has been called, getUuid() no longer
9953ca2e00c6f2a71b93c8e3c8e85aeeb03c5bd06dGreg Kaiser    // returns the UUID.
10053ca2e00c6f2a71b93c8e3c8e85aeeb03c5bd06dGreg Kaiser    // TODO(b/29547335): Remove getUuid(), add getUuidIndex(), and
10153ca2e00c6f2a71b93c8e3c8e85aeeb03c5bd06dGreg Kaiser    //     make sure setId() doesn't change the UuidIndex.
1022576cb63b3fe1592f54816625036566b9eb0793aPeng Xu    const uuid_t& getUuid() const;
10353ca2e00c6f2a71b93c8e3c8e85aeeb03c5bd06dGreg Kaiser    int32_t getId() const;
10453ca2e00c6f2a71b93c8e3c8e85aeeb03c5bd06dGreg Kaiser    void setId(int32_t id);
105589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
1068683fca395d01734ec7946e9f0595ec5d7b754c6Mathias Agopian    // LightFlattenable protocol
1078683fca395d01734ec7946e9f0595ec5d7b754c6Mathias Agopian    inline bool isFixedSize() const { return false; }
108e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian    size_t getFlattenedSize() const;
109e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian    status_t flatten(void* buffer, size_t size) const;
1108683fca395d01734ec7946e9f0595ec5d7b754c6Mathias Agopian    status_t unflatten(void const* buffer, size_t size);
111589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
112589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopianprivate:
113589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    String8 mName;
114589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    String8 mVendor;
115589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    int32_t mHandle;
116589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    int32_t mType;
117589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    float   mMinValue;
118589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    float   mMaxValue;
119589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    float   mResolution;
120589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    float   mPower;
121a48bcf62b6a26f24a0bdd2b44bb39fadce499e92Mathias Agopian    int32_t mMinDelay;
122b62013f6aafee08cfad25a2712dc32264e44f783Mathias Agopian    int32_t mVersion;
123d723bd7669b4fc88dc282d8bf8ba5ecb2849d22fDan Stoza    uint32_t mFifoReservedEventCount;
124d723bd7669b4fc88dc282d8bf8ba5ecb2849d22fDan Stoza    uint32_t mFifoMaxEventCount;
125700180487ffec09d9df1657b018a7caadac24b75Aravind Akella    String8 mStringType;
126700180487ffec09d9df1657b018a7caadac24b75Aravind Akella    String8 mRequiredPermission;
127b412f6e203b38f8047f760261a5e3dc6d0722f08Svetoslav    bool mRequiredPermissionRuntime = false;
128b412f6e203b38f8047f760261a5e3dc6d0722f08Svetoslav    int32_t mRequiredAppOp;
129d9441e4c27bb7d0b1dfe2a8b5c1ee1714442648dAravind Akella    int32_t mMaxDelay;
130f10c46ef855b6410b20ebd8b1351d4d78d8eca8eDan Stoza    uint32_t mFlags;
13153ca2e00c6f2a71b93c8e3c8e85aeeb03c5bd06dGreg Kaiser    // TODO(b/29547335): Get rid of this field and replace with an index.
13253ca2e00c6f2a71b93c8e3c8e85aeeb03c5bd06dGreg Kaiser    //     The index will be into a separate global vector of UUIDs.
13353ca2e00c6f2a71b93c8e3c8e85aeeb03c5bd06dGreg Kaiser    //     Also add an mId field (and change flatten/unflatten appropriately).
1342576cb63b3fe1592f54816625036566b9eb0793aPeng Xu    uuid_t  mUuid;
135700180487ffec09d9df1657b018a7caadac24b75Aravind Akella    static void flattenString8(void*& buffer, size_t& size, const String8& string8);
136700180487ffec09d9df1657b018a7caadac24b75Aravind Akella    static bool unflattenString8(void const*& buffer, size_t& size, String8& outputString8);
137589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian};
138589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
139589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian// ----------------------------------------------------------------------------
140589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian}; // namespace android
141589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
142589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#endif // ANDROID_GUI_SENSOR_H
143