1 /*
2 * Copyright 2021 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 <log/log.h>
18
19 #include "LnbTests.h"
20
onEvent(LnbEventType lnbEventType)21 ndk::ScopedAStatus LnbCallback::onEvent(LnbEventType lnbEventType) {
22 android::Mutex::Autolock autoLock(mMsgLock);
23 ALOGD("[vts] lnb event received. Type: %d", lnbEventType);
24 mEventReceived = true;
25 mMsgCondition.signal();
26 return ndk::ScopedAStatus::ok();
27 }
28
onDiseqcMessage(const vector<uint8_t> & diseqcMessage)29 ndk::ScopedAStatus LnbCallback::onDiseqcMessage(const vector<uint8_t>& diseqcMessage) {
30 string msg(diseqcMessage.begin(), diseqcMessage.end());
31 ALOGD("[vts] onDiseqcMessage %s", msg.c_str());
32 return ndk::ScopedAStatus::ok();
33 }
34
getLnbIds(vector<int32_t> & ids)35 AssertionResult LnbTests::getLnbIds(vector<int32_t>& ids) {
36 ndk::ScopedAStatus status;
37 status = mService->getLnbIds(&ids);
38 return AssertionResult(status.isOk());
39 }
40
openLnbById(int32_t lnbId)41 AssertionResult LnbTests::openLnbById(int32_t lnbId) {
42 ndk::ScopedAStatus status;
43 status = mService->openLnbById(lnbId, &mLnb);
44 return AssertionResult(status.isOk());
45 }
46
openLnbByName(string lnbName,int32_t & id)47 AssertionResult LnbTests::openLnbByName(string lnbName, int32_t& id) {
48 ndk::ScopedAStatus status;
49 vector<int32_t> ids;
50 status = mService->openLnbByName(lnbName, &ids, &mLnb);
51 if (status.isOk()) {
52 id = ids[0];
53 }
54 return AssertionResult(status.isOk());
55 }
56
setLnbCallback()57 AssertionResult LnbTests::setLnbCallback() {
58 if (!mLnb) {
59 ALOGW("[vts] Open Lnb first");
60 return failure();
61 }
62 mLnbCallback = ndk::SharedRefBase::make<LnbCallback>();
63 auto callbackStatus = mLnb->setCallback(mLnbCallback);
64 return AssertionResult(callbackStatus.isOk());
65 }
66
setVoltage(LnbVoltage voltage)67 AssertionResult LnbTests::setVoltage(LnbVoltage voltage) {
68 if (!mLnb) {
69 ALOGW("[vts] Open Lnb first");
70 return failure();
71 }
72 ndk::ScopedAStatus status = mLnb->setVoltage(voltage);
73 return AssertionResult(status.isOk());
74 }
75
setTone(LnbTone tone)76 AssertionResult LnbTests::setTone(LnbTone tone) {
77 if (!mLnb) {
78 ALOGW("[vts] Open Lnb first");
79 return failure();
80 }
81 ndk::ScopedAStatus status = mLnb->setTone(tone);
82 return AssertionResult(status.isOk());
83 }
84
setSatellitePosition(LnbPosition position)85 AssertionResult LnbTests::setSatellitePosition(LnbPosition position) {
86 if (!mLnb) {
87 ALOGW("[vts] Open Lnb first");
88 return failure();
89 }
90 ndk::ScopedAStatus status = mLnb->setSatellitePosition(position);
91 return AssertionResult(status.isOk());
92 }
93
sendDiseqcMessage(vector<uint8_t> diseqcMsg)94 AssertionResult LnbTests::sendDiseqcMessage(vector<uint8_t> diseqcMsg) {
95 if (!mLnb) {
96 ALOGW("[vts] Open Lnb first");
97 return failure();
98 }
99 ndk::ScopedAStatus status = mLnb->sendDiseqcMessage(diseqcMsg);
100 return AssertionResult(status.isOk());
101 }
102
closeLnb()103 AssertionResult LnbTests::closeLnb() {
104 if (!mLnb) {
105 ALOGW("[vts] Open Lnb first");
106 return failure();
107 }
108 ndk::ScopedAStatus status = mLnb->close();
109 mLnb = nullptr;
110 mLnbCallback = nullptr;
111 return AssertionResult(status.isOk());
112 }
113