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_INTERFACE_H
18 #define ANDROID_HARDWARE_RADIO_INTERFACE_H
19 
20 #include <utils/RefBase.h>
21 #include <system/radio.h>
22 #include "TunerInterface.h"
23 #include "TunerCallbackInterface.h"
24 
25 namespace android {
26 
27 class RadioInterface : public virtual RefBase
28 {
29 public:
30         /* get a sound trigger HAL instance */
31         static sp<RadioInterface> connectModule(radio_class_t classId);
32 
33         /*
34          * Retrieve implementation properties.
35          *
36          * arguments:
37          * - properties: where to return the module properties
38          *
39          * returns:
40          *  0 if no error
41          *  -EINVAL if invalid arguments are passed
42          */
43         virtual int getProperties(radio_hal_properties_t *properties) = 0;
44 
45         /*
46          * Open a tuner interface for the requested configuration.
47          * If no other tuner is opened, this will activate the radio module.
48          *
49          * arguments:
50          * - config: the band configuration to apply
51          * - audio: this tuner will be used for live radio listening and should be connected to
52          * the radio audio source.
53          * - callback: the event callback
54          * - cookie: the cookie to pass when calling the callback
55          * - tuner: where to return the tuner interface
56          *
57          * returns:
58          *  0 if HW was powered up and configuration could be applied
59          *  -EINVAL if configuration requested is invalid
60          *  -ENOSYS if called out of sequence
61          *
62          * Callback function with event RADIO_EVENT_CONFIG MUST be called once the
63          * configuration is applied or a failure occurs or after a time out.
64          */
65         virtual int openTuner(const radio_hal_band_config_t *config,
66                         bool audio,
67                         sp<TunerCallbackInterface> callback,
68                         sp<TunerInterface>& tuner) = 0;
69 
70         /*
71          * Close a tuner interface.
72          * If the last tuner is closed, the radio module is deactivated.
73          *
74          * arguments:
75          * - tuner: the tuner interface to close
76          *
77          * returns:
78          *  0 if powered down successfully.
79          *  -EINVAL if an invalid argument is passed
80          *  -ENOSYS if called out of sequence
81          */
82         virtual int closeTuner(sp<TunerInterface>& tuner) = 0;
83 
84 protected:
RadioInterface()85         RadioInterface() {}
~RadioInterface()86         virtual     ~RadioInterface() {}
87 };
88 
89 } // namespace android
90 
91 #endif // ANDROID_HARDWARE_RADIO_INTERFACE_H
92