blob: f98420d0d7260523ca55102ff88e9661533bcd1a [file] [log] [blame]
Eric Laurent73e17f22016-11-21 10:40:36 -08001/*
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
30namespace android {
31
Eric Laurent73e17f22016-11-21 10:40:36 -080032using android::hardware::Return;
33using android::hardware::broadcastradio::V1_0::Result;
34using android::hardware::broadcastradio::V1_0::IBroadcastRadio;
35using android::hardware::broadcastradio::V1_0::ITuner;
36using android::hardware::broadcastradio::V1_0::ITunerCallback;
37
38using android::hardware::broadcastradio::V1_0::BandConfig;
39using android::hardware::broadcastradio::V1_0::ProgramInfo;
40using android::hardware::broadcastradio::V1_0::MetaData;
41
42class RadioHalHidl : public RadioInterface
43{
44public:
45 RadioHalHidl(radio_class_t classId);
46
Eric Laurent73e17f22016-11-21 10:40:36 -080047 // 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 Naganovd621ac82017-01-12 17:17:45 -080080 void setHalTuner(sp<ITuner>& halTuner);
Eric Laurent73e17f22016-11-21 10:40:36 -080081 sp<ITuner> getHalTuner() { return mHalTuner; }
82
83 private:
84 virtual ~Tuner();
85
Mikhail Naganovd621ac82017-01-12 17:17:45 -080086 void onCallback(radio_hal_event_t *halEvent) const;
Eric Laurent73e17f22016-11-21 10:40:36 -080087 void handleHwFailure();
Mikhail Naganovd621ac82017-01-12 17:17:45 -080088 void sendHwFailureEvent() const;
Eric Laurent73e17f22016-11-21 10:40:36 -080089
90 sp<ITuner> mHalTuner;
Mikhail Naganovd621ac82017-01-12 17:17:45 -080091 const sp<TunerCallbackInterface> mCallback;
Eric Laurent73e17f22016-11-21 10:40:36 -080092 wp<RadioHalHidl> mParentModule;
93 };
94
95 sp<IBroadcastRadio> getService();
96 void clearService();
97
98private:
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