Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 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_MANAGER_H |
| 18 | #define ANDROID_GUI_SENSOR_MANAGER_H |
| 19 | |
Svet Ganov | 5fa32d4 | 2015-05-07 10:50:59 -0700 | [diff] [blame] | 20 | #include <map> |
| 21 | |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 22 | #include <stdint.h> |
| 23 | #include <sys/types.h> |
| 24 | |
Mathias Agopian | 1a2b83a | 2011-10-16 22:15:23 -0700 | [diff] [blame] | 25 | #include <binder/IBinder.h> |
Svet Ganov | 5fa32d4 | 2015-05-07 10:50:59 -0700 | [diff] [blame] | 26 | #include <binder/IPCThreadState.h> |
| 27 | #include <binder/IServiceManager.h> |
Mathias Agopian | 1a2b83a | 2011-10-16 22:15:23 -0700 | [diff] [blame] | 28 | |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 29 | #include <utils/Errors.h> |
| 30 | #include <utils/RefBase.h> |
| 31 | #include <utils/Singleton.h> |
| 32 | #include <utils/Vector.h> |
Aravind Akella | 7844220 | 2015-03-26 15:58:59 -0700 | [diff] [blame] | 33 | #include <utils/String8.h> |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 34 | |
| 35 | #include <gui/SensorEventQueue.h> |
| 36 | |
Peng Xu | e36e347 | 2016-11-03 11:57:10 -0700 | [diff] [blame] | 37 | #include <unordered_map> |
| 38 | |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 39 | // ---------------------------------------------------------------------------- |
| 40 | // Concrete types for the NDK |
| 41 | struct ASensorManager { }; |
| 42 | |
Peng Xu | e36e347 | 2016-11-03 11:57:10 -0700 | [diff] [blame] | 43 | struct native_handle; |
| 44 | typedef struct native_handle native_handle_t; |
| 45 | |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 46 | // ---------------------------------------------------------------------------- |
| 47 | namespace android { |
| 48 | // ---------------------------------------------------------------------------- |
| 49 | |
| 50 | class ISensorServer; |
| 51 | class Sensor; |
| 52 | class SensorEventQueue; |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 53 | // ---------------------------------------------------------------------------- |
| 54 | |
Mathias Agopian | 1a2b83a | 2011-10-16 22:15:23 -0700 | [diff] [blame] | 55 | class SensorManager : |
Svetoslav | b412f6e | 2015-04-29 16:50:41 -0700 | [diff] [blame] | 56 | public ASensorManager |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 57 | { |
| 58 | public: |
Aravind Akella | cbf4004 | 2015-07-29 18:03:48 -0700 | [diff] [blame] | 59 | static SensorManager& getInstanceForPackage(const String16& packageName); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 60 | ~SensorManager(); |
| 61 | |
Peng Xu | 2576cb6 | 2016-01-20 00:22:09 -0800 | [diff] [blame] | 62 | ssize_t getSensorList(Sensor const* const** list); |
| 63 | ssize_t getDynamicSensorList(Vector<Sensor>& list); |
Mathias Agopian | a7352c9 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 64 | Sensor const* getDefaultSensor(int type); |
Aravind Akella | a9e6cc3 | 2015-04-16 18:57:31 -0700 | [diff] [blame] | 65 | sp<SensorEventQueue> createEventQueue(String8 packageName = String8(""), int mode = 0); |
Aravind Akella | 841a592 | 2015-06-29 12:37:48 -0700 | [diff] [blame] | 66 | bool isDataInjectionEnabled(); |
Peng Xu | e36e347 | 2016-11-03 11:57:10 -0700 | [diff] [blame] | 67 | int createDirectChannel(size_t size, int channelType, const native_handle_t *channelData); |
| 68 | void destroyDirectChannel(int channelNativeHandle); |
| 69 | int configureDirectChannel(int channelNativeHandle, int sensorHandle, int rateLevel); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 70 | |
| 71 | private: |
Mathias Agopian | 1a2b83a | 2011-10-16 22:15:23 -0700 | [diff] [blame] | 72 | // DeathRecipient interface |
| 73 | void sensorManagerDied(); |
| 74 | |
Aravind Akella | cbf4004 | 2015-07-29 18:03:48 -0700 | [diff] [blame] | 75 | SensorManager(const String16& opPackageName); |
Peng Xu | 2576cb6 | 2016-01-20 00:22:09 -0800 | [diff] [blame] | 76 | status_t assertStateLocked(); |
Mathias Agopian | 1a2b83a | 2011-10-16 22:15:23 -0700 | [diff] [blame] | 77 | |
| 78 | private: |
Svet Ganov | 5fa32d4 | 2015-05-07 10:50:59 -0700 | [diff] [blame] | 79 | static Mutex sLock; |
| 80 | static std::map<String16, SensorManager*> sPackageInstances; |
| 81 | |
Peng Xu | 2576cb6 | 2016-01-20 00:22:09 -0800 | [diff] [blame] | 82 | Mutex mLock; |
| 83 | sp<ISensorServer> mSensorServer; |
| 84 | Sensor const** mSensorList; |
| 85 | Vector<Sensor> mSensors; |
| 86 | sp<IBinder::DeathRecipient> mDeathObserver; |
Svetoslav | b412f6e | 2015-04-29 16:50:41 -0700 | [diff] [blame] | 87 | const String16 mOpPackageName; |
Peng Xu | e36e347 | 2016-11-03 11:57:10 -0700 | [diff] [blame] | 88 | std::unordered_map<int, sp<ISensorEventConnection>> mDirectConnection; |
| 89 | int32_t mDirectConnectionHandle; |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 92 | // ---------------------------------------------------------------------------- |
| 93 | }; // namespace android |
| 94 | |
| 95 | #endif // ANDROID_GUI_SENSOR_MANAGER_H |