blob: b60a95e037e3e502331898f83400ade255e8c392 [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
32using android::hardware::Status;
33using android::hardware::Return;
34using android::hardware::broadcastradio::V1_0::Result;
35using android::hardware::broadcastradio::V1_0::IBroadcastRadio;
36using android::hardware::broadcastradio::V1_0::ITuner;
37using android::hardware::broadcastradio::V1_0::ITunerCallback;
38
39using android::hardware::broadcastradio::V1_0::BandConfig;
40using android::hardware::broadcastradio::V1_0::ProgramInfo;
41using android::hardware::broadcastradio::V1_0::MetaData;
42
43class RadioHalHidl : public RadioInterface
44{
45public:
46 RadioHalHidl(radio_class_t classId);
47
Eric Laurent73e17f22016-11-21 10:40:36 -080048 // RadioInterface
49 virtual int getProperties(radio_hal_properties_t *properties);
50 virtual int openTuner(const radio_hal_band_config_t *config,
51 bool audio,
52 sp<TunerCallbackInterface> callback,
53 sp<TunerInterface>& tuner);
54 virtual int closeTuner(sp<TunerInterface>& tuner);
55
56 class Tuner : public TunerInterface, public virtual ITunerCallback
57 {
58 public:
59 Tuner(sp<TunerCallbackInterface> callback, sp<RadioHalHidl> module);
60
61 // TunerInterface
62 virtual int setConfiguration(const radio_hal_band_config_t *config);
63 virtual int getConfiguration(radio_hal_band_config_t *config);
64 virtual int scan(radio_direction_t direction, bool skip_sub_channel);
65 virtual int step(radio_direction_t direction, bool skip_sub_channel);
66 virtual int tune(unsigned int channel, unsigned int sub_channel);
67 virtual int cancel();
68 virtual int getProgramInformation(radio_program_info_t *info);
69
70 // ITunerCallback
71 virtual Return<void> hardwareFailure();
72 virtual Return<void> configChange(Result result, const BandConfig& config);
73 virtual Return<void> tuneComplete(Result result, const ProgramInfo& info);
74 virtual Return<void> afSwitch(const ProgramInfo& info);
75 virtual Return<void> antennaStateChange(bool connected);
76 virtual Return<void> trafficAnnouncement(bool active);
77 virtual Return<void> emergencyAnnouncement(bool active);
78 virtual Return<void> newMetadata(uint32_t channel, uint32_t subChannel,
79 const ::android::hardware::hidl_vec<MetaData>& metadata);
80
81 void setHalTuner(sp<ITuner>& halTuner) { mHalTuner = halTuner; }
82 sp<ITuner> getHalTuner() { return mHalTuner; }
83
84 private:
85 virtual ~Tuner();
86
87 void onCallback(radio_hal_event_t *halEvent);
88 void handleHwFailure();
Eric Laurent73e17f22016-11-21 10:40:36 -080089
90 sp<ITuner> mHalTuner;
91 sp<TunerCallbackInterface> mCallback;
92 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