blob: 5b34ff4b8c38fe4ade08ccac50a56c650c4d71d8 [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
Peng Xue36e3472016-11-03 11:57:10 -070037#include <unordered_map>
38
Mathias Agopian589ce852010-07-13 22:21:56 -070039// ----------------------------------------------------------------------------
40// Concrete types for the NDK
41struct ASensorManager { };
42
Peng Xue36e3472016-11-03 11:57:10 -070043struct native_handle;
44typedef struct native_handle native_handle_t;
45
Mathias Agopian589ce852010-07-13 22:21:56 -070046// ----------------------------------------------------------------------------
47namespace android {
48// ----------------------------------------------------------------------------
49
50class ISensorServer;
51class Sensor;
52class SensorEventQueue;
Mathias Agopian589ce852010-07-13 22:21:56 -070053// ----------------------------------------------------------------------------
54
Mathias Agopian1a2b83a2011-10-16 22:15:23 -070055class SensorManager :
Svetoslavb412f6e2015-04-29 16:50:41 -070056 public ASensorManager
Mathias Agopian589ce852010-07-13 22:21:56 -070057{
58public:
Aravind Akellacbf40042015-07-29 18:03:48 -070059 static SensorManager& getInstanceForPackage(const String16& packageName);
Mathias Agopian589ce852010-07-13 22:21:56 -070060 ~SensorManager();
61
Peng Xu2576cb62016-01-20 00:22:09 -080062 ssize_t getSensorList(Sensor const* const** list);
63 ssize_t getDynamicSensorList(Vector<Sensor>& list);
Mathias Agopiana7352c92010-07-14 23:41:37 -070064 Sensor const* getDefaultSensor(int type);
Aravind Akellaa9e6cc32015-04-16 18:57:31 -070065 sp<SensorEventQueue> createEventQueue(String8 packageName = String8(""), int mode = 0);
Aravind Akella841a5922015-06-29 12:37:48 -070066 bool isDataInjectionEnabled();
Peng Xue36e3472016-11-03 11:57:10 -070067 int createDirectChannel(size_t size, int channelType, const native_handle_t *channelData);
68 void destroyDirectChannel(int channelNativeHandle);
69 int configureDirectChannel(int channelNativeHandle, int sensorHandle, int rateLevel);
Mathias Agopian589ce852010-07-13 22:21:56 -070070
71private:
Mathias Agopian1a2b83a2011-10-16 22:15:23 -070072 // DeathRecipient interface
73 void sensorManagerDied();
74
Aravind Akellacbf40042015-07-29 18:03:48 -070075 SensorManager(const String16& opPackageName);
Peng Xu2576cb62016-01-20 00:22:09 -080076 status_t assertStateLocked();
Mathias Agopian1a2b83a2011-10-16 22:15:23 -070077
78private:
Svet Ganov5fa32d42015-05-07 10:50:59 -070079 static Mutex sLock;
80 static std::map<String16, SensorManager*> sPackageInstances;
81
Peng Xu2576cb62016-01-20 00:22:09 -080082 Mutex mLock;
83 sp<ISensorServer> mSensorServer;
84 Sensor const** mSensorList;
85 Vector<Sensor> mSensors;
86 sp<IBinder::DeathRecipient> mDeathObserver;
Svetoslavb412f6e2015-04-29 16:50:41 -070087 const String16 mOpPackageName;
Peng Xue36e3472016-11-03 11:57:10 -070088 std::unordered_map<int, sp<ISensorEventConnection>> mDirectConnection;
89 int32_t mDirectConnectionHandle;
Mathias Agopian589ce852010-07-13 22:21:56 -070090};
91
Mathias Agopian589ce852010-07-13 22:21:56 -070092// ----------------------------------------------------------------------------
93}; // namespace android
94
95#endif // ANDROID_GUI_SENSOR_MANAGER_H