Eric Laurent | 73e17f2 | 2016-11-21 10:40:36 -0800 | [diff] [blame] | 1 | /* |
| 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_HARDWARE_RADIO_HAL_HIDL_H |
| 18 | #define ANDROID_HARDWARE_RADIO_HAL_HIDL_H |
| 19 | |
| 20 | #include <utils/RefBase.h> |
| 21 | #include <utils/threads.h> |
| 22 | #include "RadioInterface.h" |
| 23 | #include "TunerInterface.h" |
| 24 | #include "TunerCallbackInterface.h" |
| 25 | #include <android/hardware/broadcastradio/1.0/types.h> |
| 26 | #include <android/hardware/broadcastradio/1.0/IBroadcastRadio.h> |
| 27 | #include <android/hardware/broadcastradio/1.0/ITuner.h> |
| 28 | #include <android/hardware/broadcastradio/1.0/ITunerCallback.h> |
| 29 | |
| 30 | namespace android { |
| 31 | |
Eric Laurent | 73e17f2 | 2016-11-21 10:40:36 -0800 | [diff] [blame] | 32 | using android::hardware::Return; |
| 33 | using android::hardware::broadcastradio::V1_0::Result; |
| 34 | using android::hardware::broadcastradio::V1_0::IBroadcastRadio; |
| 35 | using android::hardware::broadcastradio::V1_0::ITuner; |
| 36 | using android::hardware::broadcastradio::V1_0::ITunerCallback; |
| 37 | |
| 38 | using android::hardware::broadcastradio::V1_0::BandConfig; |
| 39 | using android::hardware::broadcastradio::V1_0::ProgramInfo; |
| 40 | using android::hardware::broadcastradio::V1_0::MetaData; |
| 41 | |
| 42 | class RadioHalHidl : public RadioInterface |
| 43 | { |
| 44 | public: |
| 45 | RadioHalHidl(radio_class_t classId); |
| 46 | |
Eric Laurent | 73e17f2 | 2016-11-21 10:40:36 -0800 | [diff] [blame] | 47 | // RadioInterface |
| 48 | virtual int getProperties(radio_hal_properties_t *properties); |
| 49 | virtual int openTuner(const radio_hal_band_config_t *config, |
| 50 | bool audio, |
| 51 | sp<TunerCallbackInterface> callback, |
| 52 | sp<TunerInterface>& tuner); |
| 53 | virtual int closeTuner(sp<TunerInterface>& tuner); |
| 54 | |
| 55 | class Tuner : public TunerInterface, public virtual ITunerCallback |
| 56 | { |
| 57 | public: |
| 58 | Tuner(sp<TunerCallbackInterface> callback, sp<RadioHalHidl> module); |
| 59 | |
| 60 | // TunerInterface |
| 61 | virtual int setConfiguration(const radio_hal_band_config_t *config); |
| 62 | virtual int getConfiguration(radio_hal_band_config_t *config); |
| 63 | virtual int scan(radio_direction_t direction, bool skip_sub_channel); |
| 64 | virtual int step(radio_direction_t direction, bool skip_sub_channel); |
| 65 | virtual int tune(unsigned int channel, unsigned int sub_channel); |
| 66 | virtual int cancel(); |
| 67 | virtual int getProgramInformation(radio_program_info_t *info); |
| 68 | |
| 69 | // ITunerCallback |
| 70 | virtual Return<void> hardwareFailure(); |
| 71 | virtual Return<void> configChange(Result result, const BandConfig& config); |
| 72 | virtual Return<void> tuneComplete(Result result, const ProgramInfo& info); |
| 73 | virtual Return<void> afSwitch(const ProgramInfo& info); |
| 74 | virtual Return<void> antennaStateChange(bool connected); |
| 75 | virtual Return<void> trafficAnnouncement(bool active); |
| 76 | virtual Return<void> emergencyAnnouncement(bool active); |
| 77 | virtual Return<void> newMetadata(uint32_t channel, uint32_t subChannel, |
| 78 | const ::android::hardware::hidl_vec<MetaData>& metadata); |
| 79 | |
Mikhail Naganov | d621ac8 | 2017-01-12 17:17:45 -0800 | [diff] [blame] | 80 | void setHalTuner(sp<ITuner>& halTuner); |
Eric Laurent | 73e17f2 | 2016-11-21 10:40:36 -0800 | [diff] [blame] | 81 | sp<ITuner> getHalTuner() { return mHalTuner; } |
| 82 | |
| 83 | private: |
| 84 | virtual ~Tuner(); |
| 85 | |
Mikhail Naganov | d621ac8 | 2017-01-12 17:17:45 -0800 | [diff] [blame] | 86 | void onCallback(radio_hal_event_t *halEvent) const; |
Eric Laurent | 73e17f2 | 2016-11-21 10:40:36 -0800 | [diff] [blame] | 87 | void handleHwFailure(); |
Mikhail Naganov | d621ac8 | 2017-01-12 17:17:45 -0800 | [diff] [blame] | 88 | void sendHwFailureEvent() const; |
Eric Laurent | 73e17f2 | 2016-11-21 10:40:36 -0800 | [diff] [blame] | 89 | |
| 90 | sp<ITuner> mHalTuner; |
Mikhail Naganov | d621ac8 | 2017-01-12 17:17:45 -0800 | [diff] [blame] | 91 | const sp<TunerCallbackInterface> mCallback; |
Eric Laurent | 73e17f2 | 2016-11-21 10:40:36 -0800 | [diff] [blame] | 92 | wp<RadioHalHidl> mParentModule; |
| 93 | }; |
| 94 | |
| 95 | sp<IBroadcastRadio> getService(); |
| 96 | void clearService(); |
| 97 | |
| 98 | private: |
| 99 | virtual ~RadioHalHidl(); |
| 100 | |
| 101 | radio_class_t mClassId; |
| 102 | sp<IBroadcastRadio> mHalModule; |
| 103 | }; |
| 104 | |
| 105 | } // namespace android |
| 106 | |
| 107 | #endif // ANDROID_HARDWARE_RADIO_HAL_HIDL_H |