Home | History | Annotate | Download | only in libsensorndkbridge
      1 /*
      2  * Copyright (C) 2017 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 A_SENSOR_MANAGER_H_
     18 
     19 #define A_SENSOR_MANAGER_H_
     20 
     21 #include <android-base/macros.h>
     22 #include <android/frameworks/sensorservice/1.0/ISensorManager.h>
     23 #include <android/sensor.h>
     24 #include <utils/Mutex.h>
     25 #include <utils/RefBase.h>
     26 
     27 struct ALooper;
     28 
     29 struct ASensorManager {
     30     static ASensorManager *getInstance();
     31 
     32     ASensorManager();
     33     android::status_t initCheck() const;
     34 
     35     // Returns error or number of sensors returned.
     36     int getSensorList(ASensorList *list);
     37 
     38     ASensorRef getDefaultSensor(int type);
     39     ASensorRef getDefaultSensorEx(int type, bool wakeup);
     40 
     41     ASensorEventQueue *createEventQueue(
     42             ALooper *looper,
     43             int ident,
     44             ALooper_callbackFunc callback,
     45             void *data);
     46 
     47     void destroyEventQueue(ASensorEventQueue *queue);
     48 
     49 private:
     50 
     51     struct SensorDeathRecipient : public android::hardware::hidl_death_recipient
     52     {
     53         // hidl_death_recipient interface
     54         virtual void serviceDied(uint64_t cookie,
     55                 const ::android::wp<::android::hidl::base::V1_0::IBase>& who) override;
     56     };
     57 
     58     using ISensorManager = android::frameworks::sensorservice::V1_0::ISensorManager;
     59     using SensorInfo = android::hardware::sensors::V1_0::SensorInfo;
     60 
     61     static ASensorManager *sInstance;
     62     android::sp<SensorDeathRecipient> mDeathRecipient = nullptr;
     63 
     64     android::status_t mInitCheck;
     65     android::sp<ISensorManager> mManager;
     66 
     67     mutable android::Mutex mLock;
     68     android::hardware::hidl_vec<SensorInfo> mSensors;
     69     std::unique_ptr<ASensorRef[]> mSensorList;
     70 
     71     DISALLOW_COPY_AND_ASSIGN(ASensorManager);
     72 };
     73 
     74 #endif  // A_SENSOR_MANAGER_H_
     75