Home | History | Annotate | Download | only in gui
      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>
     24 #include <utils/Flattenable.h>
     25 #include <utils/String8.h>
     26 #include <utils/Timers.h>
     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 
     44 class Sensor : public ASensor, public LightFlattenable<Sensor>
     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 
     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     };
     63 
     64     Sensor(const char * name = "");
     65     Sensor(struct sensor_t const* hwSensor, int halVersion = 0);
     66     Sensor(struct sensor_t const& hwSensor, const uuid_t& uuid, int halVersion = 0);
     67     ~Sensor();
     68 
     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;
     77     int32_t getMinDelay() const;
     78     nsecs_t getMinDelayNs() const;
     79     int32_t getVersion() const;
     80     uint32_t getFifoReservedEventCount() const;
     81     uint32_t getFifoMaxEventCount() const;
     82     const String8& getStringType() const;
     83     const String8& getRequiredPermission() const;
     84     bool isRequiredPermissionRuntime() const;
     85     int32_t getRequiredAppOp() const;
     86     int32_t getMaxDelay() const;
     87     uint32_t getFlags() const;
     88     bool isWakeUpSensor() const;
     89     bool isDynamicSensor() const;
     90     bool hasAdditionalInfo() const;
     91     int32_t getReportingMode() const;
     92 
     93     // Note that after setId() has been called, getUuid() no longer
     94     // returns the UUID.
     95     // TODO(b/29547335): Remove getUuid(), add getUuidIndex(), and
     96     //     make sure setId() doesn't change the UuidIndex.
     97     const uuid_t& getUuid() const;
     98     int32_t getId() const;
     99     void setId(int32_t id);
    100 
    101     // LightFlattenable protocol
    102     inline bool isFixedSize() const { return false; }
    103     size_t getFlattenedSize() const;
    104     status_t flatten(void* buffer, size_t size) const;
    105     status_t unflatten(void const* buffer, size_t size);
    106 
    107 private:
    108     String8 mName;
    109     String8 mVendor;
    110     int32_t mHandle;
    111     int32_t mType;
    112     float   mMinValue;
    113     float   mMaxValue;
    114     float   mResolution;
    115     float   mPower;
    116     int32_t mMinDelay;
    117     int32_t mVersion;
    118     uint32_t mFifoReservedEventCount;
    119     uint32_t mFifoMaxEventCount;
    120     String8 mStringType;
    121     String8 mRequiredPermission;
    122     bool mRequiredPermissionRuntime = false;
    123     int32_t mRequiredAppOp;
    124     int32_t mMaxDelay;
    125     uint32_t mFlags;
    126     // TODO(b/29547335): Get rid of this field and replace with an index.
    127     //     The index will be into a separate global vector of UUIDs.
    128     //     Also add an mId field (and change flatten/unflatten appropriately).
    129     uuid_t  mUuid;
    130     static void flattenString8(void*& buffer, size_t& size, const String8& string8);
    131     static bool unflattenString8(void const*& buffer, size_t& size, String8& outputString8);
    132 };
    133 
    134 // ----------------------------------------------------------------------------
    135 }; // namespace android
    136 
    137 #endif // ANDROID_GUI_SENSOR_H
    138