blob: 0cff46c076231f47aaf73871fffe7dc3626463f8 [file] [log] [blame]
Mathias Agopian589ce852010-07-13 22:21:56 -07001/*
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 Ganov5fa32d42015-05-07 10:50:59 -070020#include <map>
21
Mathias Agopian589ce852010-07-13 22:21:56 -070022#include <stdint.h>
23#include <sys/types.h>
24
Mathias Agopian1a2b83a2011-10-16 22:15:23 -070025#include <binder/IBinder.h>
Svet Ganov5fa32d42015-05-07 10:50:59 -070026#include <binder/IPCThreadState.h>
27#include <binder/IServiceManager.h>
Mathias Agopian1a2b83a2011-10-16 22:15:23 -070028
Mathias Agopian589ce852010-07-13 22:21:56 -070029#include <utils/Errors.h>
30#include <utils/RefBase.h>
31#include <utils/Singleton.h>
32#include <utils/Vector.h>
Aravind Akella78442202015-03-26 15:58:59 -070033#include <utils/String8.h>
Mathias Agopian589ce852010-07-13 22:21:56 -070034
35#include <gui/SensorEventQueue.h>
36
37// ----------------------------------------------------------------------------
38// Concrete types for the NDK
39struct ASensorManager { };
40
41// ----------------------------------------------------------------------------
42namespace android {
43// ----------------------------------------------------------------------------
44
45class ISensorServer;
46class Sensor;
47class SensorEventQueue;
Mathias Agopian589ce852010-07-13 22:21:56 -070048// ----------------------------------------------------------------------------
49
Mathias Agopian1a2b83a2011-10-16 22:15:23 -070050class SensorManager :
Svetoslavb412f6e2015-04-29 16:50:41 -070051 public ASensorManager
Mathias Agopian589ce852010-07-13 22:21:56 -070052{
53public:
Aravind Akellae2806cb2015-07-29 18:03:48 -070054 static SensorManager& getInstanceForPackage(const String16& packageName);
Mathias Agopian589ce852010-07-13 22:21:56 -070055 ~SensorManager();
56
Mathias Agopiana7352c92010-07-14 23:41:37 -070057 ssize_t getSensorList(Sensor const* const** list) const;
58 Sensor const* getDefaultSensor(int type);
Aravind Akellaa9e6cc32015-04-16 18:57:31 -070059 sp<SensorEventQueue> createEventQueue(String8 packageName = String8(""), int mode = 0);
Aravind Akella841a5922015-06-29 12:37:48 -070060 bool isDataInjectionEnabled();
Mathias Agopian589ce852010-07-13 22:21:56 -070061
62private:
Mathias Agopian1a2b83a2011-10-16 22:15:23 -070063 // DeathRecipient interface
64 void sensorManagerDied();
65
Aravind Akellae2806cb2015-07-29 18:03:48 -070066 SensorManager(const String16& opPackageName);
Mathias Agopian1a2b83a2011-10-16 22:15:23 -070067 status_t assertStateLocked() const;
68
69private:
Svet Ganov5fa32d42015-05-07 10:50:59 -070070 static Mutex sLock;
71 static std::map<String16, SensorManager*> sPackageInstances;
72
Mathias Agopian1a2b83a2011-10-16 22:15:23 -070073 mutable Mutex mLock;
74 mutable sp<ISensorServer> mSensorServer;
75 mutable Sensor const** mSensorList;
76 mutable Vector<Sensor> mSensors;
77 mutable sp<IBinder::DeathRecipient> mDeathObserver;
Svetoslavb412f6e2015-04-29 16:50:41 -070078 const String16 mOpPackageName;
Mathias Agopian589ce852010-07-13 22:21:56 -070079};
80
Mathias Agopian589ce852010-07-13 22:21:56 -070081// ----------------------------------------------------------------------------
82}; // namespace android
83
84#endif // ANDROID_GUI_SENSOR_MANAGER_H