Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c6dbefae authored by Amy Zhang's avatar Amy Zhang Committed by Android (Google) Code Review
Browse files

Merge "Connect LnbClient to TunerLnb interface and handle error messages"

parents 7bc036e9 3ac0a3ee
Loading
Loading
Loading
Loading
+48 −15
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#include <android-base/logging.h>
#include <utils/Log.h>

#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<ITunerLnb> tunerLnb) {
    mTunerLnb = tunerLnb;
    mId = -1;
}

LnbClient::~LnbClient() {
    //mTunerLnb = NULL;
    mTunerLnb = NULL;
    mLnb = NULL;
    mId = -1;
}
@@ -45,19 +45,21 @@ void LnbClient::setHidlLnb(sp<ILnb> lnb) {
}

Result LnbClient::setCallback(sp<LnbClientCallback> cb) {
    // TODO: pending aidl interface
    /*if (mTunerFrontend != NULL) {
    if (mTunerLnb != NULL) {
        mAidlCallback = ::ndk::SharedRefBase::make<TunerLnbCallback>(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<uint8_t> 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<uint8_t> 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<void> HidlLnbCallback::onDiseqcMessage(const hidl_vec<uint8_t>& diseqcMes
    return Void();
}

/////////////// LnbClient Helper Methods ///////////////////////
/////////////// TunerLnbCallback ///////////////////////

TunerLnbCallback::TunerLnbCallback(sp<LnbClientCallback> lnbClientCallback)
        : mLnbClientCallback(lnbClientCallback) {}

Status TunerLnbCallback::onEvent(int lnbEventType) {
    if (mLnbClientCallback != NULL) {
        mLnbClientCallback->onEvent(static_cast<LnbEventType>(lnbEventType));
        return Status::ok();
    }
    return Status::fromServiceSpecificError(static_cast<int32_t>(Result::INVALID_STATE));
}

Status TunerLnbCallback::onDiseqcMessage(const vector<uint8_t>& diseqcMessage) {
    if (mLnbClientCallback != NULL) {
        hidl_vec<uint8_t> msg(begin(diseqcMessage), end(diseqcMessage));
        mLnbClientCallback->onDiseqcMessage(msg);
        return Status::ok();
    }
    return Status::fromServiceSpecificError(static_cast<int32_t>(Result::INVALID_STATE));
}
}  // namespace android
+12 −10
Original line number Diff line number Diff line
@@ -17,14 +17,18 @@
#ifndef _ANDROID_MEDIA_TV_LNB_CLIENT_H_
#define _ANDROID_MEDIA_TV_LNB_CLIENT_H_

//#include <aidl/android/media/tv/tuner/ITunerLnb.h>
#include <aidl/android/media/tv/tuner/BnTunerLnbCallback.h>
#include <aidl/android/media/tv/tuner/ITunerLnb.h>
#include <android/hardware/tv/tuner/1.0/ILnb.h>
#include <android/hardware/tv/tuner/1.0/ILnbCallback.h>
#include <android/hardware/tv/tuner/1.1/types.h>

#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> lnbClientCallback);

    Status onEvent(int lnbEventType);
    Status onDiseqcMessage(vector<uint8_t> diseqcMessage);
    Status onDiseqcMessage(const vector<uint8_t>& diseqcMessage);

private:
    sp<LnbClientCallback> mLnbClientCallback;
};*/
};

struct HidlLnbCallback : public ILnbCallback {

@@ -68,8 +72,7 @@ private:
struct LnbClient : public RefBase {

public:
    // TODO: add TunerLnb as parameter.
    LnbClient();
    LnbClient(shared_ptr<ITunerLnb> 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<ITunerLnb> mTunerLnb;
    shared_ptr<ITunerLnb> mTunerLnb;

    /**
     * A Lnb HAL interface that is ready before migrating to the TunerLnb.
@@ -124,7 +126,7 @@ private:
     */
    sp<ILnb> mLnb;

    //shared_ptr<TunerLnbCallback> mAidlCallback;
    shared_ptr<TunerLnbCallback> mAidlCallback;
    sp<HidlLnbCallback> mHidlCallback;

    LnbId mId;
+7 −7
Original line number Diff line number Diff line
@@ -229,15 +229,15 @@ sp<DescramblerClient> TunerClient::openDescrambler(int /*descramblerHandle*/) {
sp<LnbClient> TunerClient::openLnb(int lnbHandle) {
    if (mTunerService != NULL) {
        // TODO: handle error code
        /*shared_ptr<ITunerLnb> tunerLnb;
        mTunerService->openLnb(demuxHandle, &tunerLnb);
        return new LnbClient(tunerLnb);*/
        shared_ptr<ITunerLnb> tunerLnb;
        mTunerService->openLnb(lnbHandle, &tunerLnb);
        return new LnbClient(tunerLnb);
    }

    if (mTuner != NULL) {
        int id = getResourceIdFromHandle(lnbHandle, LNB);
        // TODO: pending aidl interface
        sp<LnbClient> lnbClient = new LnbClient();
        sp<LnbClient> lnbClient = new LnbClient(NULL);
        sp<ILnb> hidlLnb = openHidlLnbById(id);
        if (hidlLnb != NULL) {
            lnbClient->setHidlLnb(hidlLnb);
@@ -252,14 +252,14 @@ sp<LnbClient> TunerClient::openLnb(int lnbHandle) {
sp<LnbClient> TunerClient::openLnbByName(string lnbName) {
    if (mTunerService != NULL) {
        // TODO: handle error code
        /*shared_ptr<ITunerLnb> tunerLnb;
        shared_ptr<ITunerLnb> tunerLnb;
        mTunerService->openLnbByName(lnbName, &tunerLnb);
        return new LnbClient(tunerLnb);*/
        return new LnbClient(tunerLnb);
    }

    if (mTuner != NULL) {
        // TODO: pending aidl interface
        sp<LnbClient> lnbClient = new LnbClient();
        sp<LnbClient> lnbClient = new LnbClient(NULL);
        LnbId id;
        sp<ILnb> hidlLnb = openHidlLnbByName(lnbName, id);
        if (hidlLnb != NULL) {
+12 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <aidl/android/media/tv/tunerresourcemanager/ITunerResourceManager.h>
#include <aidl/android/media/tv/tuner/ITunerService.h>
#include <aidl/android/media/tv/tuner/TunerFrontendInfo.h>
#include <android/binder_parcel_utils.h>
#include <android/hardware/tv/tuner/1.1/ITuner.h>
#include <android/hardware/tv/tuner/1.1/types.h>

@@ -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<Result>(s.getServiceSpecificError());
        } else if (s.isOk()) {
            return Result::SUCCESS;
        }
        return Result::UNKNOWN_ERROR;
    }

private:
    sp<ITuner> getHidlTuner();
    sp<IFrontend> openHidlFrontendById(int id);