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 640cc8f809924706c7d683da30605f432635dd5bb6Peng Xu Sensor(const char * name = ""); 652576cb63b3fe1592f54816625036566b9eb0793aPeng Xu Sensor(struct sensor_t const* hwSensor, int halVersion = 0); 666a2d3a06caa337857cf60cfc70a9a78909ad3608Peng Xu Sensor(struct sensor_t const& hwSensor, const uuid_t& uuid, int halVersion = 0); 672576cb63b3fe1592f54816625036566b9eb0793aPeng Xu ~Sensor(); 68589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian 69589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian const String8& getName() const; 70589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian const String8& getVendor() const; 71589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian int32_t getHandle() const; 72589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian int32_t getType() const; 73589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian float getMinValue() const; 74589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian float getMaxValue() const; 75589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian float getResolution() const; 76589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian float getPowerUsage() const; 77a48bcf62b6a26f24a0bdd2b44bb39fadce499e92Mathias Agopian int32_t getMinDelay() const; 78b62013f6aafee08cfad25a2712dc32264e44f783Mathias Agopian nsecs_t getMinDelayNs() const; 79b62013f6aafee08cfad25a2712dc32264e44f783Mathias Agopian int32_t getVersion() const; 80d723bd7669b4fc88dc282d8bf8ba5ecb2849d22fDan Stoza uint32_t getFifoReservedEventCount() const; 81d723bd7669b4fc88dc282d8bf8ba5ecb2849d22fDan Stoza uint32_t getFifoMaxEventCount() const; 82700180487ffec09d9df1657b018a7caadac24b75Aravind Akella const String8& getStringType() const; 83700180487ffec09d9df1657b018a7caadac24b75Aravind Akella const String8& getRequiredPermission() const; 84b412f6e203b38f8047f760261a5e3dc6d0722f08Svetoslav bool isRequiredPermissionRuntime() const; 85b412f6e203b38f8047f760261a5e3dc6d0722f08Svetoslav int32_t getRequiredAppOp() const; 86d9441e4c27bb7d0b1dfe2a8b5c1ee1714442648dAravind Akella int32_t getMaxDelay() const; 87d723bd7669b4fc88dc282d8bf8ba5ecb2849d22fDan Stoza uint32_t getFlags() const; 889a844cf78f09953145200b4074d47589257a408cAravind Akella bool isWakeUpSensor() const; 890cc8f809924706c7d683da30605f432635dd5bb6Peng Xu bool isDynamicSensor() const; 906a2d3a06caa337857cf60cfc70a9a78909ad3608Peng Xu bool hasAdditionalInfo() const; 910e025c5af365e45e02cb75c1d46b46c7f4cd44cbAravind Akella int32_t getReportingMode() const; 9253ca2e00c6f2a71b93c8e3c8e85aeeb03c5bd06dGreg Kaiser 9353ca2e00c6f2a71b93c8e3c8e85aeeb03c5bd06dGreg Kaiser // Note that after setId() has been called, getUuid() no longer 9453ca2e00c6f2a71b93c8e3c8e85aeeb03c5bd06dGreg Kaiser // returns the UUID. 9553ca2e00c6f2a71b93c8e3c8e85aeeb03c5bd06dGreg Kaiser // TODO(b/29547335): Remove getUuid(), add getUuidIndex(), and 9653ca2e00c6f2a71b93c8e3c8e85aeeb03c5bd06dGreg Kaiser // make sure setId() doesn't change the UuidIndex. 972576cb63b3fe1592f54816625036566b9eb0793aPeng Xu const uuid_t& getUuid() const; 9853ca2e00c6f2a71b93c8e3c8e85aeeb03c5bd06dGreg Kaiser int32_t getId() const; 9953ca2e00c6f2a71b93c8e3c8e85aeeb03c5bd06dGreg Kaiser void setId(int32_t id); 100589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian 1018683fca395d01734ec7946e9f0595ec5d7b754c6Mathias Agopian // LightFlattenable protocol 1028683fca395d01734ec7946e9f0595ec5d7b754c6Mathias Agopian inline bool isFixedSize() const { return false; } 103e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian size_t getFlattenedSize() const; 104e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian status_t flatten(void* buffer, size_t size) const; 1058683fca395d01734ec7946e9f0595ec5d7b754c6Mathias Agopian status_t unflatten(void const* buffer, size_t size); 106589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian 107589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopianprivate: 108589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian String8 mName; 109589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian String8 mVendor; 110589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian int32_t mHandle; 111589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian int32_t mType; 112589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian float mMinValue; 113589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian float mMaxValue; 114589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian float mResolution; 115589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian float mPower; 116a48bcf62b6a26f24a0bdd2b44bb39fadce499e92Mathias Agopian int32_t mMinDelay; 117b62013f6aafee08cfad25a2712dc32264e44f783Mathias Agopian int32_t mVersion; 118d723bd7669b4fc88dc282d8bf8ba5ecb2849d22fDan Stoza uint32_t mFifoReservedEventCount; 119d723bd7669b4fc88dc282d8bf8ba5ecb2849d22fDan Stoza uint32_t mFifoMaxEventCount; 120700180487ffec09d9df1657b018a7caadac24b75Aravind Akella String8 mStringType; 121700180487ffec09d9df1657b018a7caadac24b75Aravind Akella String8 mRequiredPermission; 122b412f6e203b38f8047f760261a5e3dc6d0722f08Svetoslav bool mRequiredPermissionRuntime = false; 123b412f6e203b38f8047f760261a5e3dc6d0722f08Svetoslav int32_t mRequiredAppOp; 124d9441e4c27bb7d0b1dfe2a8b5c1ee1714442648dAravind Akella int32_t mMaxDelay; 125f10c46ef855b6410b20ebd8b1351d4d78d8eca8eDan Stoza uint32_t mFlags; 12653ca2e00c6f2a71b93c8e3c8e85aeeb03c5bd06dGreg Kaiser // TODO(b/29547335): Get rid of this field and replace with an index. 12753ca2e00c6f2a71b93c8e3c8e85aeeb03c5bd06dGreg Kaiser // The index will be into a separate global vector of UUIDs. 12853ca2e00c6f2a71b93c8e3c8e85aeeb03c5bd06dGreg Kaiser // Also add an mId field (and change flatten/unflatten appropriately). 1292576cb63b3fe1592f54816625036566b9eb0793aPeng Xu uuid_t mUuid; 130700180487ffec09d9df1657b018a7caadac24b75Aravind Akella static void flattenString8(void*& buffer, size_t& size, const String8& string8); 131700180487ffec09d9df1657b018a7caadac24b75Aravind Akella static bool unflattenString8(void const*& buffer, size_t& size, String8& outputString8); 132589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian}; 133589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian 134589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian// ---------------------------------------------------------------------------- 135589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian}; // namespace android 136589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian 137589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#endif // ANDROID_GUI_SENSOR_H 138