SensorManager.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. #ifndef ANDROID_GUI_SENSOR_MANAGER_H
  17. #define ANDROID_GUI_SENSOR_MANAGER_H
  18. #include <map>
  19. #include <stdint.h>
  20. #include <sys/types.h>
  21. #include <binder/IBinder.h>
  22. #include <binder/IPCThreadState.h>
  23. #include <binder/IServiceManager.h>
  24. #include <utils/Errors.h>
  25. #include <utils/RefBase.h>
  26. #include <utils/Singleton.h>
  27. #include <utils/Vector.h>
  28. #include <utils/String8.h>
  29. #include <gui/SensorEventQueue.h>
  30. // ----------------------------------------------------------------------------
  31. // Concrete types for the NDK
  32. struct ASensorManager { };
  33. // ----------------------------------------------------------------------------
  34. namespace android {
  35. // ----------------------------------------------------------------------------
  36. class ISensorServer;
  37. class Sensor;
  38. class SensorEventQueue;
  39. // ----------------------------------------------------------------------------
  40. class SensorManager :
  41. public ASensorManager
  42. {
  43. public:
  44. static SensorManager& getInstanceForPackage(const String16& packageName);
  45. ~SensorManager();
  46. ssize_t getSensorList(Sensor const* const** list) const;
  47. Sensor const* getDefaultSensor(int type);
  48. sp<SensorEventQueue> createEventQueue(String8 packageName = String8(""), int mode = 0);
  49. bool isDataInjectionEnabled();
  50. private:
  51. // DeathRecipient interface
  52. void sensorManagerDied();
  53. SensorManager(const String16& opPackageName);
  54. status_t assertStateLocked() const;
  55. private:
  56. static Mutex sLock;
  57. static std::map<String16, SensorManager*> sPackageInstances;
  58. mutable Mutex mLock;
  59. mutable sp<ISensorServer> mSensorServer;
  60. mutable Sensor const** mSensorList;
  61. mutable Vector<Sensor> mSensors;
  62. mutable sp<IBinder::DeathRecipient> mDeathObserver;
  63. const String16 mOpPackageName;
  64. };
  65. // ----------------------------------------------------------------------------
  66. }; // namespace android
  67. #endif // ANDROID_GUI_SENSOR_MANAGER_H