1 /*
2  * Copyright (C) 2022 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 #include "DirectReportChannel.h"
18 
19 namespace android {
20 namespace frameworks {
21 namespace sensorservice {
22 namespace implementation {
23 
DirectReportChannel(::android::SensorManager & manager,int channelId)24 DirectReportChannel::DirectReportChannel(::android::SensorManager& manager, int channelId)
25       : mManager(manager), mId(channelId) {}
26 
~DirectReportChannel()27 DirectReportChannel::~DirectReportChannel() {
28     mManager.destroyDirectChannel(mId);
29 }
30 
configure(int32_t sensorHandle,::aidl::android::hardware::sensors::ISensors::RateLevel rate,int32_t * _aidl_return)31 ndk::ScopedAStatus DirectReportChannel::configure(
32         int32_t sensorHandle, ::aidl::android::hardware::sensors::ISensors::RateLevel rate,
33         int32_t* _aidl_return) {
34     int token = mManager.configureDirectChannel(mId, sensorHandle, static_cast<int>(rate));
35     if (token < 0) {
36         return ndk::ScopedAStatus::fromServiceSpecificError(token);
37     }
38     *_aidl_return = token;
39     return ndk::ScopedAStatus::ok();
40 }
41 
42 } // namespace implementation
43 } // namespace sensorservice
44 } // namespace frameworks
45 } // namespace android
46