blob: 5c398a8caa2bcfd1e89fc5bda61de260df31e210 [file] [log] [blame]
Peng Xue36e3472016-11-03 11:57:10 -07001/*
2 * Copyright (C) 2016 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_SENSOR_DIRECT_CONNECTION_H
18#define ANDROID_SENSOR_DIRECT_CONNECTION_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
23#include <binder/BinderService.h>
24
Mathias Agopian801ea092017-03-06 15:05:04 -080025#include <sensor/Sensor.h>
26#include <sensor/BitTube.h>
27#include <sensor/ISensorServer.h>
28#include <sensor/ISensorEventConnection.h>
Peng Xue36e3472016-11-03 11:57:10 -070029
30#include "SensorService.h"
31
32namespace android {
33
34class SensorService;
35class BitTube;
36
37class SensorService::SensorDirectConnection: public BnSensorEventConnection {
38public:
39 SensorDirectConnection(const sp<SensorService>& service, uid_t uid,
40 const sensors_direct_mem_t *mem, int32_t halChannelHandle,
41 const String16& opPackageName);
42 void dump(String8& result) const;
43 uid_t getUid() const { return mUid; }
44 int32_t getHalChannelHandle() const;
45 bool isEquivalent(const sensors_direct_mem_t *mem) const;
46
47 // stop all active sensor report. if backupRecord is set to false,
48 // those report can be recovered by recoverAll
49 // called by SensorService when enter restricted mode
Peng Xu8cbefd72017-07-10 16:41:08 -070050 void stopAll(bool backupRecord = false);
Peng Xue36e3472016-11-03 11:57:10 -070051
52 // recover sensor reports previously stopped by stopAll(true)
53 // called by SensorService when return to NORMAL mode.
54 void recoverAll();
55
56protected:
57 virtual ~SensorDirectConnection();
58 // ISensorEventConnection functions
59 virtual void onFirstRef();
60 virtual sp<BitTube> getSensorChannel() const;
61 virtual status_t enableDisable(int handle, bool enabled, nsecs_t samplingPeriodNs,
62 nsecs_t maxBatchReportLatencyNs, int reservedFlags);
63 virtual status_t setEventRate(int handle, nsecs_t samplingPeriodNs);
64 virtual status_t flush();
65 virtual int32_t configureChannel(int handle, int rateLevel);
Peng Xu8cbefd72017-07-10 16:41:08 -070066 virtual void destroy();
Peng Xue36e3472016-11-03 11:57:10 -070067private:
68 const sp<SensorService> mService;
69 const uid_t mUid;
70 const sensors_direct_mem_t mMem;
71 const int32_t mHalChannelHandle;
72 const String16 mOpPackageName;
73
74 mutable Mutex mConnectionLock;
75 std::unordered_map<int, int> mActivated;
76 std::unordered_map<int, int> mActivatedBackup;
Peng Xu8cbefd72017-07-10 16:41:08 -070077
78 mutable Mutex mDestroyLock;
79 bool mDestroyed;
Peng Xue36e3472016-11-03 11:57:10 -070080};
81
82} // namepsace android
83
84#endif // ANDROID_SENSOR_DIRECT_CONNECTION_H
85