• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
20 #include <map>
21 
22 #include <stdint.h>
23 #include <sys/types.h>
24 
25 #include <binder/IBinder.h>
26 #include <binder/IPCThreadState.h>
27 #include <binder/IServiceManager.h>
28 
29 #include <utils/Errors.h>
30 #include <utils/RefBase.h>
31 #include <utils/Singleton.h>
32 #include <utils/Vector.h>
33 #include <utils/String8.h>
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;
48 // ----------------------------------------------------------------------------
49 
50 class SensorManager :
51     public ASensorManager
52 {
53 public:
54     static SensorManager& getInstanceForPackage(const String16& packageName);
55     ~SensorManager();
56 
57     ssize_t getSensorList(Sensor const* const** list) const;
58     Sensor const* getDefaultSensor(int type);
59     sp<SensorEventQueue> createEventQueue(String8 packageName = String8(""), int mode = 0);
60     bool isDataInjectionEnabled();
61 
62 private:
63     // DeathRecipient interface
64     void sensorManagerDied();
65 
66     SensorManager(const String16& opPackageName);
67     status_t assertStateLocked() const;
68 
69 private:
70     static Mutex sLock;
71     static std::map<String16, SensorManager*> sPackageInstances;
72 
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;
78     const String16 mOpPackageName;
79 };
80 
81 // ----------------------------------------------------------------------------
82 }; // namespace android
83 
84 #endif // ANDROID_GUI_SENSOR_MANAGER_H
85