diff --git a/media/jni/tuner/LnbClient.cpp b/media/jni/tuner/LnbClient.cpp index 7f3916fe634d6..77583b8032c80 100644 --- a/media/jni/tuner/LnbClient.cpp +++ b/media/jni/tuner/LnbClient.cpp @@ -19,6 +19,7 @@ #include #include +#include "TunerClient.h" #include "LnbClient.h" using ::android::hardware::tv::tuner::V1_0::Result; @@ -27,14 +28,13 @@ namespace android { /////////////// LnbClient /////////////////////// -// TODO: pending aidl interface -LnbClient::LnbClient() { - //mTunerLnb = tunerLnb; +LnbClient::LnbClient(shared_ptr tunerLnb) { + mTunerLnb = tunerLnb; mId = -1; } LnbClient::~LnbClient() { - //mTunerLnb = NULL; + mTunerLnb = NULL; mLnb = NULL; mId = -1; } @@ -45,19 +45,21 @@ void LnbClient::setHidlLnb(sp lnb) { } Result LnbClient::setCallback(sp cb) { - // TODO: pending aidl interface - /*if (mTunerFrontend != NULL) { + if (mTunerLnb != NULL) { mAidlCallback = ::ndk::SharedRefBase::make(cb); - mTunerLnb->setCallback(mAidlCallback); - return Result::SUCCESS; - }*/ + Status s = mTunerLnb->setCallback(mAidlCallback); + return TunerClient::getServiceSpecificErrorCode(s); + } mHidlCallback = new HidlLnbCallback(cb); return mLnb->setCallback(mHidlCallback); } Result LnbClient::setVoltage(LnbVoltage voltage) { - // TODO: pending aidl interface + if (mTunerLnb != NULL) { + Status s = mTunerLnb->setVoltage((int)voltage); + return TunerClient::getServiceSpecificErrorCode(s); + } if (mLnb != NULL) { return mLnb->setVoltage(voltage); @@ -67,7 +69,10 @@ Result LnbClient::setVoltage(LnbVoltage voltage) { } Result LnbClient::setTone(LnbTone tone) { - // TODO: pending aidl interface + if (mTunerLnb != NULL) { + Status s = mTunerLnb->setTone((int)tone); + return TunerClient::getServiceSpecificErrorCode(s); + } if (mLnb != NULL) { return mLnb->setTone(tone); @@ -77,7 +82,10 @@ Result LnbClient::setTone(LnbTone tone) { } Result LnbClient::setSatellitePosition(LnbPosition position) { - // TODO: pending aidl interface + if (mTunerLnb != NULL) { + Status s = mTunerLnb->setSatellitePosition((int)position); + return TunerClient::getServiceSpecificErrorCode(s); + } if (mLnb != NULL) { return mLnb->setSatellitePosition(position); @@ -87,7 +95,10 @@ Result LnbClient::setSatellitePosition(LnbPosition position) { } Result LnbClient::sendDiseqcMessage(vector diseqcMessage) { - // TODO: pending aidl interface + if (mTunerLnb != NULL) { + Status s = mTunerLnb->sendDiseqcMessage(diseqcMessage); + return TunerClient::getServiceSpecificErrorCode(s); + } if (mLnb != NULL) { return mLnb->sendDiseqcMessage(diseqcMessage); @@ -97,7 +108,10 @@ Result LnbClient::sendDiseqcMessage(vector diseqcMessage) { } Result LnbClient::close() { - // TODO: pending aidl interface + if (mTunerLnb != NULL) { + Status s = mTunerLnb->close(); + return TunerClient::getServiceSpecificErrorCode(s); + } if (mLnb != NULL) { return mLnb->close(); @@ -125,6 +139,25 @@ Return HidlLnbCallback::onDiseqcMessage(const hidl_vec& diseqcMes return Void(); } -/////////////// LnbClient Helper Methods /////////////////////// +/////////////// TunerLnbCallback /////////////////////// +TunerLnbCallback::TunerLnbCallback(sp lnbClientCallback) + : mLnbClientCallback(lnbClientCallback) {} + +Status TunerLnbCallback::onEvent(int lnbEventType) { + if (mLnbClientCallback != NULL) { + mLnbClientCallback->onEvent(static_cast(lnbEventType)); + return Status::ok(); + } + return Status::fromServiceSpecificError(static_cast(Result::INVALID_STATE)); +} + +Status TunerLnbCallback::onDiseqcMessage(const vector& diseqcMessage) { + if (mLnbClientCallback != NULL) { + hidl_vec msg(begin(diseqcMessage), end(diseqcMessage)); + mLnbClientCallback->onDiseqcMessage(msg); + return Status::ok(); + } + return Status::fromServiceSpecificError(static_cast(Result::INVALID_STATE)); +} } // namespace android diff --git a/media/jni/tuner/LnbClient.h b/media/jni/tuner/LnbClient.h index 533a99678efe7..24651202d73e2 100644 --- a/media/jni/tuner/LnbClient.h +++ b/media/jni/tuner/LnbClient.h @@ -17,14 +17,18 @@ #ifndef _ANDROID_MEDIA_TV_LNB_CLIENT_H_ #define _ANDROID_MEDIA_TV_LNB_CLIENT_H_ -//#include +#include +#include #include #include #include #include "LnbClientCallback.h" -//using ::aidl::android::media::tv::tuner::ITunerLnb; +using Status = ::ndk::ScopedAStatus; + +using ::aidl::android::media::tv::tuner::BnTunerLnbCallback; +using ::aidl::android::media::tv::tuner::ITunerLnb; using ::android::hardware::Return; using ::android::hardware::Void; @@ -42,17 +46,17 @@ using namespace std; namespace android { // TODO: pending aidl interface -/*class TunerLnbCallback : public BnTunerLnbCallback { +class TunerLnbCallback : public BnTunerLnbCallback { public: TunerLnbCallback(sp lnbClientCallback); Status onEvent(int lnbEventType); - Status onDiseqcMessage(vector diseqcMessage); + Status onDiseqcMessage(const vector& diseqcMessage); private: sp mLnbClientCallback; -};*/ +}; struct HidlLnbCallback : public ILnbCallback { @@ -68,8 +72,7 @@ private: struct LnbClient : public RefBase { public: - // TODO: add TunerLnb as parameter. - LnbClient(); + LnbClient(shared_ptr tunerLnb); ~LnbClient(); // TODO: remove after migration to Tuner Service is done. @@ -114,8 +117,7 @@ private: * An AIDL Tuner Lnb Singleton assigned at the first time the Tuner Client * opens an Lnb. Default null when lnb is not opened. */ - // TODO: pending on aidl interface - //shared_ptr mTunerLnb; + shared_ptr mTunerLnb; /** * A Lnb HAL interface that is ready before migrating to the TunerLnb. @@ -124,7 +126,7 @@ private: */ sp mLnb; - //shared_ptr mAidlCallback; + shared_ptr mAidlCallback; sp mHidlCallback; LnbId mId; diff --git a/media/jni/tuner/TunerClient.cpp b/media/jni/tuner/TunerClient.cpp index f5e35248fcfdc..498ba0eabb70e 100644 --- a/media/jni/tuner/TunerClient.cpp +++ b/media/jni/tuner/TunerClient.cpp @@ -229,15 +229,15 @@ sp TunerClient::openDescrambler(int /*descramblerHandle*/) { sp TunerClient::openLnb(int lnbHandle) { if (mTunerService != NULL) { // TODO: handle error code - /*shared_ptr tunerLnb; - mTunerService->openLnb(demuxHandle, &tunerLnb); - return new LnbClient(tunerLnb);*/ + shared_ptr tunerLnb; + mTunerService->openLnb(lnbHandle, &tunerLnb); + return new LnbClient(tunerLnb); } if (mTuner != NULL) { int id = getResourceIdFromHandle(lnbHandle, LNB); // TODO: pending aidl interface - sp lnbClient = new LnbClient(); + sp lnbClient = new LnbClient(NULL); sp hidlLnb = openHidlLnbById(id); if (hidlLnb != NULL) { lnbClient->setHidlLnb(hidlLnb); @@ -252,14 +252,14 @@ sp TunerClient::openLnb(int lnbHandle) { sp TunerClient::openLnbByName(string lnbName) { if (mTunerService != NULL) { // TODO: handle error code - /*shared_ptr tunerLnb; + shared_ptr tunerLnb; mTunerService->openLnbByName(lnbName, &tunerLnb); - return new LnbClient(tunerLnb);*/ + return new LnbClient(tunerLnb); } if (mTuner != NULL) { // TODO: pending aidl interface - sp lnbClient = new LnbClient(); + sp lnbClient = new LnbClient(NULL); LnbId id; sp hidlLnb = openHidlLnbByName(lnbName, id); if (hidlLnb != NULL) { diff --git a/media/jni/tuner/TunerClient.h b/media/jni/tuner/TunerClient.h index 8a1181a38fe25..733ee6bff9b72 100644 --- a/media/jni/tuner/TunerClient.h +++ b/media/jni/tuner/TunerClient.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -28,6 +29,8 @@ #include "DescramblerClient.h" #include "LnbClient.h" +using Status = ::ndk::ScopedAStatus; + using ::aidl::android::media::tv::tuner::ITunerService; using ::aidl::android::media::tv::tuner::TunerFrontendInfo; using ::aidl::android::media::tv::tunerresourcemanager::ITunerResourceManager; @@ -132,6 +135,15 @@ public: */ int getHalTunerVersion() { return mTunerVersion; } + static Result getServiceSpecificErrorCode(Status& s) { + if (s.getExceptionCode() == EX_SERVICE_SPECIFIC) { + return static_cast(s.getServiceSpecificError()); + } else if (s.isOk()) { + return Result::SUCCESS; + } + return Result::UNKNOWN_ERROR; + } + private: sp getHidlTuner(); sp openHidlFrontendById(int id);