blob: ead08d3fb6dd4e7d457abdc9cc8d3922ae94f222 [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;
Mike Ma24743862020-01-29 00:36:55 -080043 void dump(util::ProtoOutputStream* proto) const;
Peng Xue36e3472016-11-03 11:57:10 -070044 uid_t getUid() const { return mUid; }
45 int32_t getHalChannelHandle() const;
46 bool isEquivalent(const sensors_direct_mem_t *mem) const;
47
48 // stop all active sensor report. if backupRecord is set to false,
49 // those report can be recovered by recoverAll
50 // called by SensorService when enter restricted mode
Peng Xu8cbefd72017-07-10 16:41:08 -070051 void stopAll(bool backupRecord = false);
Peng Xue36e3472016-11-03 11:57:10 -070052
53 // recover sensor reports previously stopped by stopAll(true)
54 // called by SensorService when return to NORMAL mode.
55 void recoverAll();
56
57protected:
58 virtual ~SensorDirectConnection();
59 // ISensorEventConnection functions
60 virtual void onFirstRef();
61 virtual sp<BitTube> getSensorChannel() const;
62 virtual status_t enableDisable(int handle, bool enabled, nsecs_t samplingPeriodNs,
63 nsecs_t maxBatchReportLatencyNs, int reservedFlags);
64 virtual status_t setEventRate(int handle, nsecs_t samplingPeriodNs);
65 virtual status_t flush();
66 virtual int32_t configureChannel(int handle, int rateLevel);
Peng Xu8cbefd72017-07-10 16:41:08 -070067 virtual void destroy();
Peng Xue36e3472016-11-03 11:57:10 -070068private:
69 const sp<SensorService> mService;
70 const uid_t mUid;
71 const sensors_direct_mem_t mMem;
72 const int32_t mHalChannelHandle;
73 const String16 mOpPackageName;
74
75 mutable Mutex mConnectionLock;
76 std::unordered_map<int, int> mActivated;
77 std::unordered_map<int, int> mActivatedBackup;
Peng Xu8cbefd72017-07-10 16:41:08 -070078
79 mutable Mutex mDestroyLock;
80 bool mDestroyed;
Peng Xue36e3472016-11-03 11:57:10 -070081};
82
83} // namepsace android
84
85#endif // ANDROID_SENSOR_DIRECT_CONNECTION_H
86