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 | e2806cb | 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 | |
Mathias Agopian | a7352c9 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 57 | ssize_t getSensorList(Sensor const* const** list) const; |
| 58 | Sensor const* getDefaultSensor(int type); |
Aravind Akella | a9e6cc3 | 2015-04-16 18:57:31 -0700 | [diff] [blame] | 59 | sp<SensorEventQueue> createEventQueue(String8 packageName = String8(""), int mode = 0); |
Aravind Akella | 841a592 | 2015-06-29 12:37:48 -0700 | [diff] [blame] | 60 | bool isDataInjectionEnabled(); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 61 | |
| 62 | private: |
Mathias Agopian | 1a2b83a | 2011-10-16 22:15:23 -0700 | [diff] [blame] | 63 | // DeathRecipient interface |
| 64 | void sensorManagerDied(); |
| 65 | |
Aravind Akella | e2806cb | 2015-07-29 18:03:48 -0700 | [diff] [blame] | 66 | SensorManager(const String16& opPackageName); |
Mathias Agopian | 1a2b83a | 2011-10-16 22:15:23 -0700 | [diff] [blame] | 67 | status_t assertStateLocked() const; |
| 68 | |
| 69 | private: |
Svet Ganov | 5fa32d4 | 2015-05-07 10:50:59 -0700 | [diff] [blame] | 70 | static Mutex sLock; |
| 71 | static std::map<String16, SensorManager*> sPackageInstances; |
| 72 | |
Mathias Agopian | 1a2b83a | 2011-10-16 22:15:23 -0700 | [diff] [blame] | 73 | mutable Mutex mLock; |
| 74 | mutable sp<ISensorServer> mSensorServer; |
| 75 | mutable Sensor const** mSensorList; |
| 76 | mutable Vector<Sensor> mSensors; |
| 77 | mutable sp<IBinder::DeathRecipient> mDeathObserver; |
Svetoslav | b412f6e | 2015-04-29 16:50:41 -0700 | [diff] [blame] | 78 | const String16 mOpPackageName; |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 81 | // ---------------------------------------------------------------------------- |
| 82 | }; // namespace android |
| 83 | |
| 84 | #endif // ANDROID_GUI_SENSOR_MANAGER_H |