SensorManager.h revision 09034f076e7897732479c8aef6284938aafbfbfe
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 ANDROID_FRAMEWORKS_SENSORSERVICE_V1_0_SENSORMANAGER_H 18#define ANDROID_FRAMEWORKS_SENSORSERVICE_V1_0_SENSORMANAGER_H 19 20#include <jni.h> 21 22#include <mutex> 23 24#include <android/frameworks/sensorservice/1.0/ISensorManager.h> 25#include <android/frameworks/sensorservice/1.0/types.h> 26#include <hidl/MQDescriptor.h> 27#include <hidl/Status.h> 28#include <sensor/SensorManager.h> 29#include <utils/Looper.h> 30 31namespace android { 32namespace frameworks { 33namespace sensorservice { 34namespace V1_0 { 35namespace implementation { 36 37using ::android::hardware::sensors::V1_0::SensorType; 38using ::android::hardware::hidl_handle; 39using ::android::hardware::hidl_memory; 40using ::android::hardware::Return; 41 42struct SensorManager final : public ISensorManager { 43 44 SensorManager(JavaVM* vm); 45 ~SensorManager(); 46 47 // Methods from ::android::frameworks::sensorservice::V1_0::ISensorManager follow. 48 Return<void> getSensorList(getSensorList_cb _hidl_cb) override; 49 Return<void> getDefaultSensor(SensorType type, getDefaultSensor_cb _hidl_cb) override; 50 Return<void> createAshmemDirectChannel(const hidl_memory& mem, uint64_t size, createAshmemDirectChannel_cb _hidl_cb) override; 51 Return<void> createGrallocDirectChannel(const hidl_handle& buffer, uint64_t size, createGrallocDirectChannel_cb _hidl_cb) override; 52 Return<void> createEventQueue(const sp<IEventQueueCallback> &callback, createEventQueue_cb _hidl_cb); 53 54private: 55 // Block until ::android::SensorManager is initialized. 56 ::android::SensorManager& getInternalManager(); 57 sp<::android::Looper> getLooper(); 58 59 std::mutex mInternalManagerMutex; 60 ::android::SensorManager* mInternalManager = nullptr; // does not own 61 62 std::mutex mLooperMutex; 63 sp<::android::Looper> mLooper; 64 65 JavaVM* mJavaVm; 66}; 67 68} // namespace implementation 69} // namespace V1_0 70} // namespace sensorservice 71} // namespace frameworks 72} // namespace android 73 74#endif // ANDROID_FRAMEWORKS_SENSORSERVICE_V1_0_SENSORMANAGER_H 75