blob: fa88fbc360a6ba4608efb13e22ab7940ee485d4e [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
Arthur Ishiguro14c96b12020-03-26 15:09:03 -070057 void updateSensorSubscriptions();
58
59 void setSensorAccess(bool hasAccess);
Peng Xue36e3472016-11-03 11:57:10 -070060protected:
61 virtual ~SensorDirectConnection();
62 // ISensorEventConnection functions
63 virtual void onFirstRef();
64 virtual sp<BitTube> getSensorChannel() const;
65 virtual status_t enableDisable(int handle, bool enabled, nsecs_t samplingPeriodNs,
66 nsecs_t maxBatchReportLatencyNs, int reservedFlags);
67 virtual status_t setEventRate(int handle, nsecs_t samplingPeriodNs);
68 virtual status_t flush();
69 virtual int32_t configureChannel(int handle, int rateLevel);
Peng Xu8cbefd72017-07-10 16:41:08 -070070 virtual void destroy();
Peng Xue36e3472016-11-03 11:57:10 -070071private:
Arthur Ishiguro14c96b12020-03-26 15:09:03 -070072 bool hasSensorAccess() const;
Peng Xue36e3472016-11-03 11:57:10 -070073 const sp<SensorService> mService;
74 const uid_t mUid;
75 const sensors_direct_mem_t mMem;
76 const int32_t mHalChannelHandle;
77 const String16 mOpPackageName;
78
79 mutable Mutex mConnectionLock;
80 std::unordered_map<int, int> mActivated;
81 std::unordered_map<int, int> mActivatedBackup;
Peng Xu8cbefd72017-07-10 16:41:08 -070082
Arthur Ishiguro14c96b12020-03-26 15:09:03 -070083 std::atomic_bool mHasSensorAccess = true;
84
Peng Xu8cbefd72017-07-10 16:41:08 -070085 mutable Mutex mDestroyLock;
86 bool mDestroyed;
Peng Xue36e3472016-11-03 11:57:10 -070087};
88
89} // namepsace android
90
91#endif // ANDROID_SENSOR_DIRECT_CONNECTION_H
92