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 | |
| 37 | // ---------------------------------------------------------------------------- |
| 38 | // Concrete types for the NDK |
| 39 | struct ASensorManager { }; |
| 40 | |
| 41 | // ---------------------------------------------------------------------------- |
| 42 | namespace android { |
| 43 | // ---------------------------------------------------------------------------- |
| 44 | |
| 45 | class ISensorServer; |
| 46 | class Sensor; |
| 47 | class SensorEventQueue; |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 48 | // ---------------------------------------------------------------------------- |
| 49 | |
Mathias Agopian | 1a2b83a | 2011-10-16 22:15:23 -0700 | [diff] [blame] | 50 | class SensorManager : |
Svetoslav | b412f6e | 2015-04-29 16:50:41 -0700 | [diff] [blame] | 51 | public ASensorManager |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 52 | { |
| 53 | public: |
Aravind Akella | cbf4004 | 2015-07-29 18:03:48 -0700 | [diff] [blame] | 54 | static SensorManager& getInstanceForPackage(const String16& packageName); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 55 | ~SensorManager(); |
| 56 | |
Peng Xu | 2576cb6 | 2016-01-20 00:22:09 -0800 | [diff] [blame] | 57 | ssize_t getSensorList(Sensor const* const** list); |
| 58 | ssize_t getDynamicSensorList(Vector<Sensor>& list); |
Mathias Agopian | a7352c9 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 59 | Sensor const* getDefaultSensor(int type); |
Aravind Akella | a9e6cc3 | 2015-04-16 18:57:31 -0700 | [diff] [blame] | 60 | sp<SensorEventQueue> createEventQueue(String8 packageName = String8(""), int mode = 0); |
Aravind Akella | 841a592 | 2015-06-29 12:37:48 -0700 | [diff] [blame] | 61 | bool isDataInjectionEnabled(); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 62 | |
| 63 | private: |
Mathias Agopian | 1a2b83a | 2011-10-16 22:15:23 -0700 | [diff] [blame] | 64 | // DeathRecipient interface |
| 65 | void sensorManagerDied(); |
| 66 | |
Aravind Akella | cbf4004 | 2015-07-29 18:03:48 -0700 | [diff] [blame] | 67 | SensorManager(const String16& opPackageName); |
Peng Xu | 2576cb6 | 2016-01-20 00:22:09 -0800 | [diff] [blame] | 68 | status_t assertStateLocked(); |
Mathias Agopian | 1a2b83a | 2011-10-16 22:15:23 -0700 | [diff] [blame] | 69 | |
| 70 | private: |
Svet Ganov | 5fa32d4 | 2015-05-07 10:50:59 -0700 | [diff] [blame] | 71 | static Mutex sLock; |
| 72 | static std::map<String16, SensorManager*> sPackageInstances; |
| 73 | |
Peng Xu | 2576cb6 | 2016-01-20 00:22:09 -0800 | [diff] [blame] | 74 | Mutex mLock; |
| 75 | sp<ISensorServer> mSensorServer; |
| 76 | Sensor const** mSensorList; |
| 77 | Vector<Sensor> mSensors; |
| 78 | sp<IBinder::DeathRecipient> mDeathObserver; |
Svetoslav | b412f6e | 2015-04-29 16:50:41 -0700 | [diff] [blame] | 79 | const String16 mOpPackageName; |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 82 | // ---------------------------------------------------------------------------- |
| 83 | }; // namespace android |
| 84 | |
| 85 | #endif // ANDROID_GUI_SENSOR_MANAGER_H |