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);
58     ssize_t getDynamicSensorList(Vector<Sensor>& list);
59     Sensor const* getDefaultSensor(int type);
60     sp<SensorEventQueue> createEventQueue(String8 packageName = String8(""), int mode = 0);
61     bool isDataInjectionEnabled();
62 
63 private:
64     // DeathRecipient interface
65     void sensorManagerDied();
66 
67     SensorManager(const String16& opPackageName);
68     status_t assertStateLocked();
69 
70 private:
71     static Mutex sLock;
72     static std::map<String16, SensorManager*> sPackageInstances;
73 
74     Mutex mLock;
75     sp<ISensorServer> mSensorServer;
76     Sensor const** mSensorList;
77     Vector<Sensor> mSensors;
78     sp<IBinder::DeathRecipient> mDeathObserver;
79     const String16 mOpPackageName;
80 };
81 
82 // ----------------------------------------------------------------------------
83 }; // namespace android
84 
85 #endif // ANDROID_GUI_SENSOR_MANAGER_H
86